本文介绍了$手表不工作时,模型范围更新。$适用于指令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经在那里我已经添加了手表上的指令范围的existingfiles模型指令。当在通过范围模式的变革。$应用,存在手表听众没有呼叫。
i have a directive where i have added a watch on the 'existingfiles' model of the directive scope. When there is change in the model through scope.$apply, there is no call to listener in watch.
下面是指令code,请让我知道,如果我在这里失去了一些东西,
Here is the directive code, kindly let me know if i am missing something here,
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
};
})
这是我的呼吁指令,
Here is my call to directive,
<div fileupload-plugin ng-model="existingfiles"></div>
请让我知道如何确保模型正确观看
Kindly let me know how to make sure that model is watched properly
推荐答案
问题已经给予真实作为手表调用$第三个参数解决。
请在这里找到,在第三个参数的更多信息,
Problem has been resolved by giving 'true' as third parameter of $watch call.Please find here, the more information on third parameter,
角文档
这篇关于$手表不工作时,模型范围更新。$适用于指令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!