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 code above does is to execute the function "onResizeFunction" every time the window is resized.
Inside the function I have "console.log" which does the element ID trace.
When I resize the window, the ID appears 2 times in a row, that is, the function is executed 2 times, even though there is only 1 element in the HTML with the "modal" class, where the directive is applied. p>