更新时间:2022-11-19 08:52:40
创建自定义指令:
app.directive("myResize", function($parse) {返回 {链接:postLink};函数 postLink(scope, elem, attrs) {elem.on("resize", function (e) {var rs = $parse(attrs.myResize);rs(scope, {$event: e});范围.$应用();});}});
用法:
欲了解更多信息,
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.
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,