我有內部控制器的以下功能:納克重複 - 當陣列在控制器改變不更新視圖,使用控制器作爲語法
app.controller("myCtrl", function(myServ, $scope){
var ctrlScope = this;
ctrlScope.myData = [];
function getData(){
myServ.getData().then(function(data){
$scope.$evalAsync(function(){
ctrlScope.myData = data;
});
});
}
getData(); // myData is initialised properly
ctrlScope.update = function(){
// Data has already changed in backend
getData(); //myData inside controller is updated but ng-repeat is not able to show on the view the updated array
};
});
HTML:
<div data-ng-controller="myCtrl as mc">
<span data-ng-repeat="d in mc.myData">{{d.name}}</span>
<button data-ng-click="mc.update()"> Update </button>
</div>
getData()
即使控制器已更新數據,也會正確初始化ng-repeat
,但無法更新視圖。
如何更新這些數據?它是否與第三方像jQuery? – AranS
它正在通過一些其他操作更新,未在此處顯示以保持問題清晰。 –
[[d.name]]替換爲大括號 – gyc