Angular with haml: Dynamic html classes

Posted Over 7 years ago. Visible to the public.

A haml angular 1 template with

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

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 }}")
License
Source code in this card is licensed under the MIT License.
Posted to makandra dev (2016-11-11 10:07)