所以我知道我可以像这样使用@Input
将数据从父母传递给孩子。
<app-component [data]="data"></app-component>
@Input() data: any;
现在我有一个像这样动态添加的组件。
HTML
<app-header></app-header>
<div #entry [vimeoId]="vimeoId"></div>
<router-outlet></router-outlet>
APP.COMPONENT.TS
ngOnInit() {
this._videoService.videoSource.subscribe((result) => {
if (result !== '') {
this.vimeoId = result;
this.createComponent();
}
});
}
createComponent() {
const factory = this._resolver.resolveComponentFactory(VideoComponent);
const component = this.entry.createComponent(factory);
}
现在这不起作用,我收到此错误
[Angular] Can't bind to 'vimeoId' since it isn't a known property of 'div'.
现在我知道为什么会出现此错误,原因是div没有@Input这样。我的问题是如何将数据传递给动态创建的子组件?
谢谢