ディレクティブ スコープの「existingfiles」モデルにウォッチを追加したディレクティブがあります。scope.$apply を介してモデルに変更がある場合、watch でリスナーへの呼び出しはありません。
ここにディレクティブ コードがあります。ここで何か不足している場合はお知らせください。
directive('fileuploadPlugin', function() {
var linkFn;
linkFn = function(scope, element, attrs) {
angular.element(element).ready(function() {
jQuery('#fileupload').fileupload({
done: function (e, data) {
scope.$apply(function(scope) {
for(var i=0; i < data.result.filesuploaded.length; i++){
scope.existingfiles.push(data.result.filesuploaded[i]);
};
});
}
});
scope.$watch('existingfiles', function(newValue, oldValue) {
element.imagesLoaded(function() {
scope.$apply( function() {
element.masonry({
itemSelector : '.box'
});
});
});
});
};
return {
templateUrl : 'templates/fileupload_plugin.htm',
restrict : 'A',
scope : {
existingfiles : '=ngModel',
},
link : linkFn
};
})
これがディレクティブへの私の呼び出しです。
<div fileupload-plugin ng-model="existingfiles"></div>
モデルが適切に監視されていることを確認する方法を教えてください