角度JS模型更新不起作用

angular js model update not working

本文关键字:不起作用 更新 模型 JS 角度      更新时间:2023-09-26

我有一个模型,它使用ajax请求的结果进行更新。

myController = function($scope){
  makeAjaxRequest(function(result){
   $scope.ResultsView = result.data;
  });
}

视图似乎没有自动更新

<div ng-controller="myController">
 <span ng-model="ResultView.cost"></span>
</div>

成本字段未更新。

更新:我是否必须像cost等一样单独更新每个字段?angularjs 有简单的方法来做到这一点吗?

你需要

使用scope$apply方法:

makeAjaxRequest(function(result){
   $scope.$apply(function () {
       $scope.ResultsView = result.data;
   });   
});