我已經看到這個問題很多,但我沒有嘗試過的解決方案正在爲我工作。我嘗試使用$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 –