私はいくつかの問題があります。指示commentsFeedback
のng-repeat
に私はユーザーのコメントをいくつか示しています。 フォームをクリックした後、私はサーバーから新しいオブジェクトを取得します。私は$scope.users[0].atrb
をresponse.resultに更新していますが、指示のng-repeat
はこのアップデートを書き換えません。 scope.users[0].atrb
が変更された後、サーバーまたはどのディレクティブの要素を更新するための応答を取得した後ディレクティブ内の要素を示した再する方法角度指令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;
}
}
});
?
Heh、それは私の決定です。 コントローラー '$ watch'に挿入し、' link:function() ' ' $ scope. $ watch( function(oldVal、newVal){ updateCommentsList(); }}ディレクティブから削除しました。 function updateCommentsList(){ $ scope.somelist = $ scope.users [0] .atrb } ' これをより効果的に行うための任意のバリアントはありますか? – VolArt