How to safely clean up AngularJS event binding in a directive

前端 未结 3 1419
面向向阳花
面向向阳花 2020-12-15 04:23

I have an Angular directive that sets an element\'s height equal to the inner height of the browser window (+/- a given offset). This directive responds to the window\'s \"r

3条回答
  •  不知归路
    2020-12-15 05:17

    For one, there is absolutely nothing wrong with using JQuery and AngularJS together.

    That aside, what I like to do is have a body directive which listens to window.on('resize', ...) and writes the size into $rootScope.windowSize. Then have another directive on the element, to $watch("windowSize", ...) and set to width as needed. (You don't actually have to expose the size in $scope - you can instead use require).

提交回复
热议问题