【问题标题】:Angular2 property binding with ComponentFactoryResolver [duplicate]Angular2 与 ComponentFactoryResolver 的属性绑定 [重复]
【发布时间】:2016-11-24 15:50:23
【问题描述】:

我正在尝试在一个 HTML 页面中引导多个 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

【问题讨论】:

    标签: angular property-binding


    【解决方案1】:

    Angular2 中一般不支持对根元素标签的绑定。

    您可以使用

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

    另见Initialize Angular 2 component with attribute

    【讨论】:

      猜你喜欢
      • 2017-01-30
      • 2017-02-08
      • 2015-09-28
      • 2017-03-10
      • 2017-08-10
      • 2016-08-18
      • 2017-04-28
      • 2016-03-28
      相关资源
      最近更新 更多