我已经看到这个问题很多,但我没有尝试过的解决方案正在为我工作。我尝试使用$apply()
,这给了我一个错误,指出摘要循环已经在运行。我尝试使用Dot“。”符号,但没有变化。我甚至尝试过使用超时和承诺,但仍不会在视图中更新。Angularjs范围变量不会更新查看
下面是HTML:
<th colspan="4" ng-class="{'ssqtrue': deficiencies === false , 'ssqfalse': deficiencies === true}">
<span ng-model="definfo">{{definfo}}</span>
</th>
这里是我的控制器代码:
$scope.recalculateDashboard = function (goToDashboard) {
contractorService
.calculateScores()
.success(function() {
getscoringDetails();
getDefInfo();
if (goToDashboard) {
$scope.tabs[0].active = true;
}
}).error(function (reason) {
console && console.log(reason.statusText);
genericErrorAlertHandler();
});
};
function getDefInfo() {
contractorService.getDeficiencyInfo()
.success(function (data) {
$scope.$apply(function() {
$scope.definfo = data;
});
if ($scope.definfo == 'No Deficiencies Found') {
$scope.deficiencies = false;
} else {
$scope.deficiencies = true;
}
}).error(function (reason) {
console && console.log(reason.statusText);
genericErrorAlertHandler();
});
}
对于我的生活,我也弄不清是怎么回事的。任何援助非常感谢!
您不能将'ng-model'绑定到'span',并且使用'then'函数而不是'success',因为它不推荐使用。 –
阅读[ng-model和ng-bind]之间的区别(https://stackoverflow.com/a/12420157/5447994) – Thamilan
ng-bind首先出现并且没有工作,所以我将其更改为ng-model –