本文介绍了加载第二个组件会导致“为组件SidebarComponent指定的模板不是字符串".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我刚刚开始学习角度知识,我试图创建一个简单的仪表板.
I have just started learning angular and i tried to create a simple dashboard.
我已经创建了两个componentents,DashboardComponent和SidebarComponent.
I've created 2 componentents, DashboardComponent and SidebarComponent.
仪表板加载正常,但是当我加载SidebarComponent时,浏览器出现错误为组件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:
SidebarComponent:
import { Component } from '@angular/core';
@Component({
selector: 'sidebar-component',
templateUrl: './sidebar.component.ts',
styleUrls: ['./sidebar.component.scss']
})
export class SidebarComponent {}
App.module
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 { }
它们两者也都已加载到app.component中
Both of them are also loaded in app.component
<sidebar-component></sidebar-component>
<dashboard></dashboard>
推荐答案
错误说明了一切……
您指的是.ts
文件而不是.html
.
更改此行:
templateUrl: './sidebar.component.ts'
收件人:
templateUrl: './sidebar.component.html'
这篇关于加载第二个组件会导致“为组件SidebarComponent指定的模板不是字符串".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!