【问题标题】:How to bind ngStyle to ng-conent in angular2如何在 Angular 2 中将 ngStyle 绑定到 ng-content
【发布时间】:2016-07-26 18:31:56
【问题描述】:

我尝试将 ngStyle 绑定到 ng-content,它不起作用,请参见下面的示例:

<ng-content select="panel-one" [ngStyle]="{'width':size+'px'}"></ng-content>

我在网上搜索只找到以下解决方案,

::content >>> panel-one {width:50px}

=>来自https://plnkr.co/edit/T5CoP5qmd4nzIPAFjLNQ?p=preview

但它不能动态改变样式值。

【问题讨论】:

    标签: angular ng-style angular2-ngcontent


    【解决方案1】:

    &lt;ng-content&gt; 永远不会添加到 DOM。它只是 Angular2 的内部占位符。 [ngStyle] 根本没有任何作用。

    也许使用包装器可以满足您的需求

      <div [ngStyle]="{'width':size+'px'}">
        <ng-content select="panel-one" ></ng-content>
      </div>
    

    【讨论】:

      猜你喜欢
      • 2017-08-10
      • 2018-03-19
      • 2020-03-22
      • 1970-01-01
      • 2019-04-22
      • 1970-01-01
      • 1970-01-01
      • 2017-04-12
      • 2017-06-30
      相关资源
      最近更新 更多