星期五, 3月 27, 2015

[AngularJS] 小踩雷筆記: ng-class的css name使用-符合

如果你的class name使用了-符號,搭配使用ng-class時,請加上''符號,不然則會失效
請參考: http://stackoverflow.com/questions/15557151/ngclass-style-with-dash-in-key
After hours of hacking around, it turns out the dash gets interpolated! Quotes are needed.
 class="icon-home" ng-class="{'icon-white': someBooleanValue}">
I hope this helps someone from tearing their hair out.
UPDATE:
In older versions of Angular, using a backslash also does the trick, but not in the newer versions.
 class="icon-home" ng-class="{icon\-white: someBooleanValue}">
The former is probably preferred, since you can search for it in your favorite editor.

沒有留言:

張貼留言

留個話吧:)

其他你感興趣的文章

Related Posts with Thumbnails