2016-11-24 151 views
1

我試圖在一個HTML頁面中引導多個angular2組件。Angular2屬性與ComponentFactoryResolver綁定

<body> 
    <cart id="cart">Loading CartComponent content here ...</cart> 
    <p>The text between components</p> 
    <item [itemId]="1" [itemName]="Cool Item1" id="item-1">Loading ItemComponent id=1 content here ...</item> 
    <p>The text between components</p> 
    <item [itemId]="2" [itemName]="Cool Item2" id="item-2">Loading ItemComponent id=2 content here ...</item> 
    <p>The text between components</p> 
    <item [itemId]="3" [itemName]="Cool Item3" id="item-3">Loading ItemComponent id=3 content here ...</item> 

    </body> 

到目前爲止,除了從服務器傳遞給index.html的屬性的屬性綁定之外,一切正常。

這裏是plunker https://plnkr.co/edit/5DbVda?p=preview

回答

2

綁定根元素的標籤上通常不Angular2支持。

您可以解決使用

export class AppComponent { 
    constructor(elementRef:ElementRef) { 
    console.log(elementRef.nativeElement.getAttribute('inputField)); 
    } 
} 

又見Initialize Angular 2 component with attribute