2016-04-19 7 views
0

変数をinclude htmlページからmy appに渡したいと思います。Angular2 htmlページからappに変数を注入する

注:コンポーネント間を渡す方法は分かっていますが、質問はアプリ外からのものです!

例 私のhtmlページ:

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

と私は私のアプリで "はcustomerId" 変数を使用できるようにしたいです。

import {Component} 'angular2/core'からインポートします。

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

これはどのようにすることができますか?

私は入力を試みましたが、成功しませんでした。

@Input("customerId") customerId; 

ありがとう。

答えて

1

@Input()バインディングはルートコンポーネントではサポートされていません。

は、あなたが使用することができます回避策としてもhttps://github.com/angular/angular/issues/1858

を参照してください

constructor(public elementRef: ElementRef) { 
    var native = this.elementRef.nativeElement; 
    var myattr = native.getAttribute("myattr"); 
} 
関連する問題