[英]External Module in RC5: Can't bind to 'X' since it isn't a known property
In the process of updating RC4 => RC5 and have pulled several components into modules. 在更新RC4 => RC5的过程中,已将几个组件拉入模块。 Now, get a runtime error: Unhandled Promise rejection: Template parse errors: Can't bind to 'X' since it isn't a known property of 'Y'
. 现在,得到一个运行时错误: Unhandled Promise rejection: Template parse errors: Can't bind to 'X' since it isn't a known property of 'Y'
。
declarations
property of the app's @NgModule()
decorator, it works. 如果我将组件类添加到应用程序的@NgModule()
装饰器的declarations
属性中,则它将起作用。 imports
property of the app's @NgModule()
do I get this error. 仅当组件类在外部模块中并且将该模块添加到应用程序的@NgModule()
的imports
属性中时, @NgModule()
此错误。 External Module Code 外部模块代码
export class ExampleConfig {
public name: string;
}
@Component({
selector: 'example',
template: '<strong>{{ config?.name }}</strong>'
})
export class ExampleComponent {
@Input() config: ExampleConfig;
}
@NgModule({
declarations: [ExampleComponent]
})
export class ExampleModule {}
App Module Code 应用模块代码
@Component({
selector: 'my-app',
template: '<h2>Hello <example [config]="exampleConfig"></example></h2>'
})
export class App {
constructor() {
this.exampleConfig = new ExampleConfig();
this.exampleConfig.name = 'World';
}
protected exampleConfig: ExampleConfig;
}
@NgModule({
imports: [BrowserModule, ExampleModule],
declarations: [App],
bootstrap: [App]
})
export class AppModule {}
Can't bind to 'X' since it isn't a known property 无法绑定到“ X”,因为它不是已知属性
If you see this error, then be sure you have not included your Component in your bootstrap module file, Do the following 如果看到此错误,请确保您的引导模块文件中未包含组件,请执行以下操作
if you have 3 Components 如果您有3个组件
1. app.component.ts
2. greeting.service.ts
3. hello.ts
then in you main bootstrapping file include everything as follows 然后在您的主引导文件中包含以下所有内容
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } '@angular/core';
import { MyApp } from './app.component'
import {Welcome} from './services/welcome';
import {Hello} from './hello.component';
@NgModule({
imports: [BrowserModule],
providers:[Welcome],
declarations: [MyApp
,Hello
],
bootstrap: [MyApp]
})
export class MyAppModule {
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.