Angular2 属性 与 ComponentFactoryResolver 绑定

Angular2 property binding with ComponentFactoryResolver

我正在尝试在一个 HTML 页面中 bootstrap 多个 angular2 组件。

  <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));
  }
}

另见