![]() |
VOOZH | about |
Class binding in Angular makes it very easy to set the class property of a view element. We can set or remove the CSS class names from an element's class attribute with the help of class binding.
We bind a class of a DOM element to a field that is a defined property in our Typescript Code. Its syntax is like that of property binding.
Syntax:
<element [class] = "typescript_property">
Approach:
Example 1: Setting the class element using class binding.
app.component.html
app.component.ts
Output:
π ImageExample 2: setting the class element using a function.
app.component.html
app.component.ts
Output:
π Image