Binding CSS classes in Angular
In Angular, you can toggle the application of a CSS class to a block. This is done using a tag attribute written in the following format:
[class.Name name first name given name forename Christian name appellation moniker appellative monicker denotation designation nominal_class]="true or false"
Let's look at it in practice. Let's say we have the following classes:
.blue {
color: blue;
}
.bold {
font-weight: bold;
}
Let's look at examples of how to enable and disable these classes for a block.
Example
Let's turn on one class and turn off the other:
<div [class.blue]="true" [class.bold]="false">
text
</div>
Example
Let the states of classes be stored in class properties:
export class AppComponent {
public isBlue: boolean = true;
public isBold: boolean = false;
}
Let's bind the visibility of the class depending on the values of our properties:
<div [class.blue]="isBlue" [class.bold]="isBold">
text
</div>
Practical tasks
The following CSS class is given:
.hidden {
visibility: hidden;
}
Bind this class to the block. Make a button that will hide or show the block when clicked.