Answer the question
In order to leave comments, you need to log in
How to bind correctly in Angular?
Yesterday there was a dispute
And so, there are two options for binding, for example, a class:
1) there is an array of data and the class is taken from there
div [class]="elelent.class"
elements: {
id: number;
class: string;
}
div [class]="getClass(id)"
getClass(id: number): string {}
Answer the question
In order to leave comments, you need to log in
All computed or just asynchronous things need to be stored in an Observable. There will be a complete analogue of your computed.
For example, there is a variable
src = new BehaviorSubject(1);
From it we calculate the class
myClass = this.src.pipe(map(v => v === 1 ? 'one' : 'two'))
div [ngClass]="myClass | async"
src.next(2)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question