Skip to content

Instantly share code, notes, and snippets.

@killerchip
Created January 1, 2018 06:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save killerchip/a6fce548ca71d5f5d251f3022b7b2edb to your computer and use it in GitHub Desktop.
Save killerchip/a6fce548ca71d5f5d251f3022b7b2edb to your computer and use it in GitHub Desktop.
Angular cheatsheet: Directives / NgClass

NgClass

  <div [ngClass]="{bordered: true, 'white-background': false}"></div>
  <div [ngClass]="['class1','class2','class3']"></div>

tip: You can use a classes object in your code and bind it to template

component code

  public classesObj = { /* implement logic that build classes in the object*/ }; // e.g. {bordered: true; strongly: true}

HTML template

  <div [ngClass]="classesObj"></div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment