0

I want to pass variables from the including html page to the my app.

Note: I know how to pass between components but the question is from outside the app!

Example My html page:

  <body>
    <my-app customerId="123">Loading...</my-app>
  </body>

and i want to be able to use "customerId" variable in my app.

import {Component} from 'angular2/core';

@Component({
    selector: 'my-app',
    template: '<h1>My First Angular 2 App</h1>'
})
export class AppComponent { 
  customerId;
}

How can this be done?

I tried with input but with no success.

  @Input("customerId") customerId;

Thanks.

Roninio
  • 1,761
  • 1
  • 17
  • 24

1 Answers1

1

@Input() bindings are not supported on the root component.

See also https://github.com/angular/angular/issues/1858

As a workaround you can use

constructor(public elementRef: ElementRef) {
    var native = this.elementRef.nativeElement;
    var myattr = native.getAttribute("myattr");
}
Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567