Angular classes code example
Example 1: Angular 8 ngClass If
[ngClass]="(step=='step1')?'my-class1':'my-class2'"
Example 2: angular ngclass
content_copy
...
...
...
...
...
Example 3: Angular 8 ngClass If
[ngClass]="{'my-class': step=='step1', 'my-class2':step=='step2' }"
Example 4: ngclass angular
5,
'red': number <= 5,
}" >
//if the number is over 5, the class 'green' will be added to the div.
//if the number is below or equal 5, the class 'red' will be added to the div.
Example 5: create class angular
// to create a model class, we first need to create a new file
//f.e person.ts
export class Person {
constructor(
public name: string,
public lastName: string,
public age:number
) {}
}
//now that we have the model class we can create arrays that contain Person class elements
.
.
public people: Person[];
constructor(){
this.people = [
new Person ('Carla','Smith', 20 ),
new Person ('Carlos','Smith', 25 ),
new Person ('Andrea','Johnson', 23 ),
];
}