Is it possible to pass an @Input value to app.component in Angular 2?

前端 未结 1 1958
深忆病人
深忆病人 2021-01-04 18:34

I\'m using ASP.Net to render my Angular 2 app, and the only RAZOR page I have is the _Layout.cshtml and I would love to be able to pass some init data from RAZOR into my boo

相关标签:
1条回答
  • 2021-01-04 18:52

    It's not possible to use inputs for main components (bootstrapped ones). You need to get the attribute directly from the DOM:

    @Component({
      selector: 'my-app',
      template: "<div id='mainBody'>Test:{{test}}</div>",
      directives: [MenuBarComponent, ROUTER_DIRECTIVES]
    })
    export class AppComponent {
      constructor(private elementRef:ElementRef) {
        this.test = this.elementRef.nativeElement.getAttribute('test');
      }
    }
    
    0 讨论(0)
提交回复
热议问题