我有3个根组件,由根AppModule引导.
你如何为其中一个组件指定@input()参数?
也不
<app-modal [id]="'hard-coded value'"></app-modal> <app-modal [id]="constantExportedByAppmodule"></app-modal>
由AppModalComponent获取:
@input() id: string;
它是未定义的.
据我所知,你不能将@input()传递给bootstraped组件.
但您可以使用其他方法来做到这一点 – 将值作为属性传递.
index.html:
<my-app myAttribute="myAttributeValue">
<div>Loading...</div>
</my-app>
app.component.ts:
@Component({
selector: 'my-app',templateUrl: 'app.component.html',styleUrls: ['app.component.css']
})
export class AppComponent {
constructor(private elementRef:ElementRef) {
let myAttribute = this.elementRef.nativeElement.getAttribute('myAttribute');
}
}