Angular NgStyle Example | NgStyle Directive In Angular 9/8

Rate this post

Angular NgStyle Example | NgStyle Directive In Angular 9/8

In this post we will give you information about Angular NgStyle Example | NgStyle Directive In Angular 9/8. Hear we will give you detail about Angular NgStyle Example | NgStyle Directive In Angular 9/8And how to use it also give you demo for it if it is necessary.

Here, i will show you angular ng style conditional example. This tutorial will give you simple example of ngstyle with condition angular. you will learn ngstyle with condition in angular. In this article, we will implement a *ngstyle condition in angular example.

You can easily use ng style in angular 6, angular 7, angular 8 and angular 9 example.

*ngStyle allows you to write css on element. In this example i will give you two example one will be simple add css using object and another example of adding css using component function.

Let’s see bellow example angular ngStyle directive example.

Example 1: ngStyle with a Object

src/app/app.component.html

<h1>Angular ngStyle Directive Example – ItSolutionstuff.com</h1>

<button [ngStyle]=”{background: ‘red’}”>Click Me!</button>

Example 2: ngStyle with a Function

src/app/app.component.html

<h1>Angular ngStyle Directive Example – ItSolutionstuff.com</h1>
<button [ngStyle]=”addButtonStyles()”>Click Me!</button>

src/app/app.component.ts
import { Component } from ‘@angular/core’;
@Component({
selector: ‘my-app’,
templateUrl: ‘./app.component.html’,
styleUrls: [ ‘./app.component.css’ ]
})
export class AppComponent {
addButtonStyles(){
return {
‘background’: ‘blue’,
‘padding’: ’12px’
}
}
}

I hope it can help you…

Hope this code and post will helped you for implement Angular NgStyle Example | NgStyle Directive In Angular 9/8. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs

See also  angularjs insert update delete example in php

Hi, I’m Jaydip Gondaliya. I help build websites, grow businesses, big and small. If that is what you want, contact me. I’m currently available for freelance work. info@yttags.com

Leave a Comment