Specify @Input() parameter for Angular root component/module

前端 未结 2 664
失恋的感觉
失恋的感觉 2020-12-20 12:08

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

2条回答
  •  遥遥无期
    2020-12-20 12:17

    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 :

    
        
    Loading...

    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');
        }
    }
    

提交回复
热议问题