1

Does AngularJS have equivalent to this:

elementObject.addEventListener("resize", myFunction);

I thought about about watches, but I don't think it's the good solution.

2 Answers 2

2

Create a custom directive:

app.directive("myResize", function($parse) {
    return {
        link: postLink
    };
    function postLink(scope, elem, attrs) {
        elem.on("resize", function (e) {
            var rs = $parse(attrs.myResize);
            rs(scope, {$event: e});
            scope.$apply();
        });
    }
});

Usage:

<div my-resize="$ctrl.myFunction($event)">
</div>

For more information,

Sign up to request clarification or add additional context in comments.

Comments

0

You can also do this: HTML:

<div resize-me></div>

JavaScript:

myApp.directive('resizeMe', ['$window', function($window) {
    return {
        link: function(scope, elem, attrs) {
            angular.element(elem).bind('resize', function() {
                //do something on resize
            })
        }
    }
}])

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.