Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Loading second component causes "The template specified for component SidebarComponent is not a string"

I have just started learning angular and i tried to create a simple dashboard.

I've created 2 componentents, DashboardComponent and SidebarComponent.

Dashboard loads fine, but when i load SidebarComponent i'm getting a error on browser "The template specified for component SidebarComponent is not a string"enter image description here

SidebarComponent:

import { Component } from '@angular/core';

@Component({
    selector: 'sidebar-component',
    templateUrl: './sidebar.component.ts',
    styleUrls: ['./sidebar.component.scss']
})
export class SidebarComponent {}

App.module

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';

import { AppComponent } from './app.component';
import { DashboardComponent } from './dashboard/dashboard.component';
import { SidebarComponent } from './sidebar/sidebar.component';

@NgModule({
  declarations: [
    AppComponent,
    DashboardComponent,
    SidebarComponent
  ],
  imports: [
    BrowserModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

Both of them are also loaded in app.component

<sidebar-component></sidebar-component>
<dashboard></dashboard>
like image 515
ekclone Avatar asked Jun 16 '17 00:06

ekclone


1 Answers

The error speaks for itself...

You're referring to a .ts file instead of .html.

Change this line:

templateUrl: './sidebar.component.ts'

to:

templateUrl: './sidebar.component.html'
like image 177
developer033 Avatar answered Nov 07 '22 06:11

developer033