Angular2属性与ComponentFactoryResolver绑定

Angular2属性与ComponentFactoryResolver绑定

问题描述:

我试图在一个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

绑定根元素的标签上通常不Angular2支持。

您可以解决使用

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

又见Initialize Angular 2 component with attribute