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