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 online protection

Rails Long Term Support

Rails LTS provides security patches for old versions of Ruby on Rails (2.3, 3.2, 4.2 and 5.2)

  • Prevents you from data breaches and liability risks
  • Upgrade at your own pace
  • Works with modern Rubies
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)