Read more

Angular with haml: Dynamic html classes

Deleted user #4117
November 11, 2016Software engineer

A haml angular 1 template with

.thing(class="is-{{:: item.type }}")
Illustration UI/UX Design

UI/UX Design by makandra brand

We make sure that your target audience has the best possible experience with your digital product. You get:

  • Design tailored to your audience
  • Proven processes customized to your needs
  • An expert team of experienced designers
Read more Show archive.org snapshot

will be compiled (by haml) to

<div class="is-{{:: item.type thing }}"></div>

which is not what you want! It will also crash in angular (unless thing is a valid variable in your angular directive) with Error: [$parse:syntax] Syntax Error: Token 'thing' is an unexpected token at column 11 of the expression [item.type thing]

Solution 1: Use ng-class instead of class

.thing(ng-class='"is-{{ item.type }}"')

Solution 2: Don't let haml build the class statement:

%div(class="thing is-{{ item.type }}")
Posted to makandra dev (2016-11-11 11:07)