javascript - Angular 2.0 and ng-style -


i building angular 2.0 component , want control it's style dynamically (using ng-style). after quick view on angular 2's docs tried this:

<div class="theme-preview" ng-style="{'font-size': fontsize}">   {{fontsize}} </div> 

and saw size printed inside div did not affected style. fontsize 1 of component's property bindings', meaning component gets parent this:

<my-component [font-size]="size" /> 

while inside component have:

@component({   selector: 'xxx',   properties: ['fontsize'] }) 

am missing here?

update

people still reach answer, i've updated plnkr beta.1. 2 things have changed far

  • ngstyle no longer necessary explicitly added in directives property. it's part of common directives added default.
  • the syntax has changed, must camel case.

example

@component({   selector : 'my-cmp',   template : `     <div class="theme-preview" [ngstyle]="{'font-size': fontsize+'px'}">    {{fontsize}}   </div>` }) class mycmp {   @input('font-size') fontsize; }  @component({    selector: 'my-app',   directives: [mycmp],   template: `     <my-cmp [font-size]="100"></my-cmp>   ` }) 

see plnkr (updated beta.1)


Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -