我已阅读有关此问题的主题,例如:The view is not updated in AngularJS但我仍然不明白如何将它应用到我的简单示例中。
我有这个功能:
function MyPageView($scope) {
var myModel = new MyModel();
$scope.myModel = myModel;
}
当 myModel
在代码的其他地方更新时(当用户点击、交互、发送 XHR 请求时)它不会更新我的 View 。我知道我需要用 $apply 做点什么,但我不知道在哪里以及如何做。
有人可以向我解释如何解决这个简单用例的问题吗?
我的模型看起来像这样(如果这个问题是必要的)——它里面没有 AngularJS 代码:
var MyModel = function() {
var _this = this;
...
_this.load = function(){...};
_this.updateModel = function(){...};
...
return _this;
}
添加一个 JSfiddle 示例: http://jsfiddle.net/DAk8r/2/
最佳答案
更新模型后在 Controller 中尝试 $scope.$apply()
关于javascript - 当 AngularJS 中的模型更新时, View 不会更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14374440/