Issue
I’m using Angular 2 and I’ve written the below code:
<div [style.width.px]="width">some texts </div>
I’ve also tried:
<div [ngStyle]="{'width.px': width}">some texts </div>
export class MyComponent
{
width: number = 150;
}
But it doesn’t bind the width to the div
element.
What am I doing wrong?
Solution
Works fine for me
@Component({
selector: 'my-app',
styles: [`div { border: 3px solid red; }`]
template: `
<div>
<h2>Hello {{name}}</h2>
<div [style.width.px]="width">some texts </div>
</div>
`,
})
export class App {
name:string;
width: number = 250;
constructor() {
this.name = 'Angular2'
}
}