You can use ngStyle
to dynamically add the css
to your page from json.
<div [ngStyle]="{'color': variable ? 'red' : 'blue'}"></div>
An another example:
<div md-card-avatar [ngStyle]="{'background-image': 'url(' + post.avatar + ')', 'background-size': 'cover' }"></div>
here I have loaded background image from json-data.
Related Contents:
- How do I return the response from an Observable/http/async call in angular?
- How to load external scripts dynamically in Angular?
- Property ‘…’ has no initializer and is not definitely assigned in the constructor
- Angular 2 Sibling Component Communication
- Can’t bind to ‘ngModel’ since it isn’t a known property of ‘input’
- How do I download a file with Angular2 or greater
- How to implement RouteReuseStrategy shouldDetach for specific routes in Angular 2
- Importing lodash into angular2 + typescript application
- angular 2 how to return data from subscribe
- (change) vs (ngModelChange) in angular
- JS : Convert Array of Strings to Array of Objects
- Angular: Can’t find Promise, Map, Set and Iterator
- Angular 4.3.3 HttpClient : How get value from the header of a response?
- Typescript Type ‘string’ is not assignable to type
- Angular 2 router event listener
- In Angular, how do you determine the active route?
- Angular 2 Karma Test ‘component-name’ is not a known element
- Angular2 component’s “this” is undefined when executing callback function
- Deep copy an array in Angular 2 + TypeScript
- Angular 6: How to set response type as text while making http call
- How to call JavaScript functions from Typescript in Angular 5?
- How to do the chain sequence in rxjs
- Angular4 – No value accessor for form control
- How to Pass data from child to parent component Angular
- Angular 2: TypeError: l_thing0 is undefined in [{{thing.title}} in AppComponent@4:44]
- ngOnInit not being called when Injectable class is Instantiated
- Angular2 too many file requests on load
- Angular 4 pass data between 2 not related components
- using external JS libraries in my angular 2 project
- Load existing components dynamically Angular 2 Final Release
- npm WARN … requires a peer of … but none is installed. You must install peer dependencies yourself
- Is it a good practice using Observable with async/await?
- What does Angular 2 hashtags in template mean?
- Angular 5 Scroll to top on every Route click
- Prevent IE11 caching GET call in Angular 2
- Angular 2 – communication of typescript functions with external js libraries
- Rxjs toPromise() deprecated
- Converting an image to base64 in angular 2
- How to check for isBrowser in Angular 4
- Unraveling Angular 2 book, Chapter 1, Example 5
- Angular 8 – Lazy loading modules : Error TS1323: Dynamic import is only supported when ‘–module’ flag is ‘commonjs’ or ‘esNext’
- Angular: In which lifecycle hook is input data available to the Component
- Cast int to enum strings in Typescript
- Highlight the search text – angular 2
- Correct way Provide DomSanitizer to Component with Angular 2 RC6
- Whats the difference between using a class and interface?
- Angular 2 typescript invoke javascript function
- Angular 2 binding/events not working when adding template as innerHTML
- How to iterate using ngFor loop Map containing key as string and values as map iteration
- Storing Objects in localStorage