0
I have the following "directve":
app.directive('modal', ['$window', function ($window) {
return {
restrict: 'C',
link: function (scope, element, attrs) {
scope.onResizeFunction = function() {
console.log(attrs.id);
};
scope.onResizeFunction();
angular.element($window).bind('resize', function() {
scope.onResizeFunction();
scope.$apply();
});
}
}
}]);
What the above code does is perform the "onResizeFunction" function every time the window is resized.
Inside the function I have "console.log" which traces the element ID.
When resize the window, the ID appears 2 times in a row, that is, the function is executed 2 times, even if there is only 1 element in the HTML with the class "modal", where the "Directive" is applied.