I've created some directives which have some functions, something like this:
myCtrl.directive('myDirective', function () {
return {
restrict: 'E',
scope: {
'something': '='
},
link: function (scope, el, attr) {
function func1(){
//some stuff
scope.$apply();
}
function func2(){
//some stuff
scope.$apply();
}
function func3(){
//some stuff
scope.$apply();
}
//...
}
}
});
I have to call scope.$apply()
in all the functions to update the view. In addition I don't want to define them in the controller. I don't know if there is a trick to avoid this kind of pattern. It is working but I think it's not a good solution.
UPDATE
There are more than 10 directives which we've created for some shapes, e.g. rectangle, circle, square etc. In these functions, which I called $apply
in them, some methods like drag and scale are implemented. So I need to call $apply
to modify changes in model and consequently the view will be updated. I don't know how can I make them able to aware scope
automatically unless I write about 100 functions in a controller!
In addition, I'm using some 3rd party libraries like d3.js
. Some event like clicked
are bounded for calling these functions.