gpt4 book ai didi

javascript - 未评估的 ng 类

转载 作者:太空宇宙 更新时间:2023-11-04 03:37:07 24 4
gpt4 key购买 nike

考虑这个 js 代码:

  // class inside controller TODO: refactor
$scope.$watch('concat.country', function(newValue) {
if (highRisk.indexOf(newValue) !== -1) {
alert(newValue + " is a high risk country");
$scope.riskClass = "highRisk";
} else if (mediumRisk.indexOf(newValue) !== -1) {
alert(newValue + " is a medium risk country");
$scope.riskClass = "mediumRisk";
} else {
$scope.riskClass = "";
}
});

有模板

 <div ng-class="{{riskClass}}" class="col-lg-10">

逻辑很好。我可以在 Chrome 中看到 ng-class 设置为正确的值,但背景没有改变,元素检查器也没有显示类。

为什么不评估 ng-class? {{riskClass}} 不合法/不正确?

PS 我知道这段代码远非完美。

最佳答案

如果类名在字符串中,则不需要 ng-class...

<div class="col-lg-10 {{riskClass}}">

当你有一些你想添加类的 bool 条件时,你应该使用 ng-class。

关于javascript - 未评估的 ng 类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25388711/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com