Angular2 is providing ngStyle to set CSS dynamically as like Angular1, but syntax is different. We can assign CSS element  by using JavaScript element.

Using ngStyle

Observe below highlighted code. [] represents one way binding
<button (click)="myStyle={color:'red'}">Set Color</button>
<button (click)="myStyle={'background-color':'blue'}">Set Background color</button>
<button (click)="myStyle = {}">clear</button>
<div [ngStyle]="myStyle">Click above button to set text color</div>
View DEMO

Using element style property

Observe below code. Here style.width was bound to myStyleWidth
<div [style.width.px]="myStyleWidth" [style.border]="myBorderStyle">
  sample text in div
</div>
Div Width :: <input [(ngModel)]="myStyleWidth"/>
border style :: <input [(ngModel)]="myBorderStyle"/>
View DEMO

5 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. Set CSS to element with angular2. It is an employment boost reviews styling sheet which have some stylish function for all the developers. Hope you guys can choose reading data which programmer telling you the most cause here are some simple effects which are increased the demand for styling.

    ReplyDelete
  3. covers up please drop by to state would be an ideal blog. There will be people who should analyze this blog. All the peruser will adequately comprehend the system for portland printers. This will be a best considered writing for a blog.

    ReplyDelete
  4. Are you endeavoring to make you language structure mind blowing. By then I train you to come and get a couple of targets from which you can without a lot of a stretch get helping material for you. That public speaking coach time is throwing a ton of essential for you since you are excited about such a learning cycle.

    ReplyDelete
  5. While composing my own spine chiller, the first in an arrangement, I got to considering how long an arrangement should run for? Given that it's effective, how far should an author keep delivering his arrangement prior to giving it up? Also, Mba Assignment Writing Service, what rules would it be a good idea for him to/she use to oversee the arrangement duration? Captivated, I started to analyze some new spine chiller arrangement books.

    ReplyDelete

Blogroll

Follow this blog by Email

Popular Posts