I have 3 root components that get bootstrapped by the root AppModule
.
How do you go about specifying an @Input()
parameter to one of those components?
Neither
<app-modal [id]="'hard-coded value'"></app-modal>
<app-modal [id]="constantExportedByAppmodule"></app-modal>
are picked up by AppModalComponent
:
@Input() id: string;
It is undefined.
As far as I know, you can not pass @Input() to a bootstraped component.
But you can use another way to do that - pass the value as an attribute.
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');
}
}