Change style of pseudo elements in angular2

You can achieve what you need with CSS variables. In your style sheet you can set the background image like this: .featured-image:after { content: ”; background-image: var(–featured-image); } After that you can programmatically set this variable on the same element or higher up in the DOM tree: <div class=”featured-image” [ngStyle]=”{‘–featured-image’: featuredImage}”> More about CSS variables … Read more

angularjs ng-style: background-image isn’t working

It is possible to parse dynamic values in a couple of way. Interpolation with double-curly braces: ng-style=”{‘background-image’:’url({{myBackgroundUrl}})’}” String concatenation: ng-style=”{‘background-image’: ‘url(‘ + myBackgroundUrl + ‘)’}” ES6 template literals: ng-style=”{‘background-image’: `url(${myBackgroundUrl})`}”

How to set div width using ng-style

The syntax of ng-style is not quite that. It accepts a dictionary of keys (attribute names) and values (the value they should take, an empty string unsets them) rather than only a string. I think what you want is this: <div ng-style=”{ ‘width’ : width, ‘background’ : bgColor }”></div> And then in your controller: $scope.width=”900px”; … Read more

Angular – How to apply [ngStyle] conditions

For a single style attribute, you can use the following syntax: <div [style.background-color]=”style1 ? ‘red’ : (style2 ? ‘blue’ : null)”> I assumed that the background color should not be set if neither style1 nor style2 is true. Since the question title mentions ngStyle, here is the equivalent syntax with that directive: <div [ngStyle]=”{‘background-color’: style1 … Read more

tech