Skip to main content

Attribute Directives: ngClass, ngStyle and Custom Directives

Learn Attribute Directives: ngClass, ngStyle and Custom Directives (Phase 4 · Directives and Pipes (Core), Angular) with worked examples, diagrams and interview questions. Free on JavaSchoolLab.

Class and style bindings • Attribute directives change the appearance or behaviour of an existing element. The simplest tools are plain bindings: [class.active]="isActive" , [class]="classes" , [style.color]="color" , [style.width.px]="w" . • [ngClass] and [ngStyle] accept strings, arrays or objects for several classes/styles at once. Prefer the direct [class] / [style] bindings in new code, which are faster and more flexible.

More lessons in Phase 4 · Directives and Pipes (Core)