在Angular 2中使用嵌套组件
我有一个声明了几个组件的模块,当我在模板中使用指令语法时,Angular找不到组件-我得到了这个错误在Angular 2中使用嵌套组件,angular,typescript,nested,angular-components,Angular,Typescript,Nested,Angular Components,我有一个声明了几个组件的模块,当我在模板中使用指令语法时,Angular找不到组件-我得到了这个错误 “test-cell-map”不是已知元素: 1.如果“测试单元图”是角度分量, 然后确认它是此模块的一部分。 2.如果“测试单元映射”是Web组件,则添加“自定义元素\u架构” 发送到此组件的“@NgModule.schema”以抑制此消息。 这是组件模块 import { BrowserModule } from '@angular/platform-browser';
“test-cell-map”不是已知元素:
1.如果“测试单元图”是角度分量,
然后确认它是此模块的一部分。
2.如果“测试单元映射”是Web组件,则添加“自定义元素\u架构”
发送到此组件的“@NgModule.schema”以抑制此消息。
这是组件模块
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';
import { AppComponent } from './app.component';
import { TestCellMapComponent } from './test-cell-map/test-cell-map.component';
@NgModule({
declarations: [
AppComponent,
TestCellMapComponent
],
imports: [
BrowserModule,
FormsModule,
HttpModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
这就是顶级组件的外观
import { Component } from '@angular/core';
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
title = 'app works!';
}
及其关联的模板
{{title}}
您的TestCellMapComponent选择器有问题
<h1>
{{title}}
<app-test-cell-map></app-test-cell-map> //<<<<===== changed
</h1>
{{title}}
//也请发布TestCellMapComponent代码。是的,这是答案->我使用Angular CLI,出于某种原因,它在子组件中的选择器名称中添加了“app”OK。发生!原因是这是在angular-cli.json in前缀中配置的。