在更新RC4 =>的过程中RC5并将多个组件拉入模块中。现在,获取运行时错误:Unhandled Promise rejection: Template parse errors: Can't bind to 'X' since it isn't a known property of 'Y'
。
declarations
装饰器的@NgModule()
属性中,它可以正常工作。 imports
的{{1}}属性时才会出现此错误。这是plunkr。
外部模块代码
@NgModule()
应用模块代码
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 {}
答案 0 :(得分:2)
在material2源代码中挖掘,看起来你必须向模块装饰器的exports
属性添加组件:
@NgModule({
declarations: [ExampleComponent],
exports: [ExampleComponent]
})
export class ExampleModule {}
答案 1 :(得分:0)
无法绑定到'X',因为它不是已知属性
如果您看到此错误,请确保未在引导程序模块文件中包含组件,请执行以下操作
如果您有3个组件
it('should do something', function(done) {
var func_spy = sinon.spy(obj, 'method');
func_spy.on('called', function() {
// check something
done();
});
}
然后在你的主引导文件中包含以下所有内容
1. app.component.ts
2. greeting.service.ts
3. hello.ts