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

给你一囗甜甜゛ 提交于 2019-12-08 15:13:23

问题


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"

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>

回答1:


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'


来源:https://stackoverflow.com/questions/44578976/loading-second-component-causes-the-template-specified-for-component-sidebarcom

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!