私はこの問題を何時間も研究してきましたが、最終的に plunker で再現しました。
これが私の問題です:
外部リソースをテンプレートとして使用するカスタマイズされたディレクティブを ng-repeat と組み合わせると、モデルが変更されている間、ビューが正しくレンダリングされませんでした。
私の例では、リンクをクリックするとモデルが置き換えられますが、古いデータは消去されていません。
template: 'stringTemplate'
の代わりに使用するとtemplateUrl: 'urlToTemplate'
、正常に動作します。バグなのかどうなのかはまだわかりませんが…
部分的なコード:
angular.module('test', [])
.run(function($rootScope) {
$rootScope.topics = [{
content: 'Click here to change reply',
replys: [{
content: 'Reply test...',
}]
}];
})
.directive('topic', function() {
return {
replace: true,
restrict: 'E',
templateUrl: 'topic.htm',
link: function(scope) {
scope.reply = function(input) {
scope.topic.replys = [{ content: '"Reply test..." should be replaced, but it\'s not!' }];
}
}
};
})
.directive('reply', function() {
return {
replace: true,
restrict: 'E',
// template: '<div><div ng-bind="reply.content"></div></div>' //this works fine
templateUrl: 'reply.htm' // same content
};
});