1
我有一些麻煩。在指令commentsFeedback
在ng-repeat
我正在顯示一些用戶評論。 在表單響應後,我從服務器獲取新對象。我正在更新$scope.users[0].atrb
到response.result,但指令中的ng-repeat
不會重寫此更新。Angular指令ng-repeat和範圍problemm
myApp.controller('myCtrl', ['$scope', '$http', 'Myfactory',
function ($scope, $http, Myfactory){
$scope.commentFunk = function(comment, commentForm){
$http.post('url/', {text: comment.text})
.success(function (response) {
$scope.users[0].atrb = response.result;
})
.error( function (response) {
console.log('Response', response);
})
}
}]);
myApp.directive('commentsFeedback', function() {
return {
restrict: 'AE',
template: "<h2>Comments</h2>" +
"<div ng-repeat='key in some_list'>" +
"<div ng-repeat='item in key.comments_list'><h4>{$ key.name $}</h4> <b>{$ item.author $}:</b> {$ item.text $}" +
"</div></div>",
link:function (scope, element, attrs){
scope.some_list = scope.users[0].atrb;
}
}
});
如何從服務器或如何更新元素指令scope.users[0].atrb
後已改變越來越響應之後,重新顯示在指令中的元素?
嘿,這是我的決定。 (); 我插入到控制器'$ watch'並從指令delete'function()' '$ scope。$ watch( function(oldVal,newVal){ updateCommentsList(); }); 函數updateCommentsList(){ $ scope.somelist = $ scope.users [0] .atrb }' 是否有任何變種更有效地做到這一點? – VolArt