Using class with angular vs ng-class while using a mixed expression

前端 未结 1 1035
礼貌的吻别
礼貌的吻别 2021-01-07 18:21

I have a div that I want to give a dynamic class with AngularJS.

The div is withing an ng-repeat statement where lang.prefix is first en then sv

Using the fo

1条回答
  •  离开以前
    2021-01-07 18:50

    The book you have mentioned may have talked about the problems of using ng-class and class {{}} interpolations together wherein updates in the interpolation removes the ng-class classes, this problem has already been resolved, reference. Thus, using interpolation within class attributes is totally fine, and does not break good practice because both has its own quirks.

    Your usage of ng-class however is incorrect, you have to concatenate the literal string value with your scope string variable:

    but I think it is much preferable to use your first example instead:

    0 讨论(0)
提交回复
热议问题