Apply classes to an element.
-
Default Angular bindings (
[class.x]
and[ngClass]
) do not allow to bind dynamic class-names based onboolean
/string
values. -
@HostBinding
can not providengClass
functionality, if we want to bind classes from component.
$ ng add @novyk/sx-class
<div [sxClass]="{color: 'red', active: true, primary: false}">
<!--<div class="color-red active">-->
constructor(private sxClass: SxClass) {}
...
this.sxClass.apply({color: 'red', active: true, primary: false});
Adds to element: class="color-red active"