0

I try to bind ngStyle to ng-content, it doesn't work, see below example:

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

I search on internet only find below solution,

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

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

but it can not dynamic change the style value.

Ivan zhao
  • 1
  • 3

1 Answers1

1

<ng-content> is never added to the DOM. It's just an internal placeholder for Angular2. The [ngStyle] doesn't have any effect at all.

Maybe using a wrapper does what you want

  <div [ngStyle]="{'width':size+'px'}">
    <ng-content select="panel-one" ></ng-content>
  </div>
Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567