2017-07-11 152 views

回答

2

創建自定義指令:

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(); 
     }); 
    } 
}); 

用法:

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

欲瞭解更多信息,

0

你也可以這樣做: 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 
      }) 
     } 
    } 
}])