[英]How to intercept a function in angularJs
I have a directive called "my-dir" that I can't modified inside my project我有一个名为“my-dir”的指令,我无法在我的项目中修改它
<div ng-controller="MyCtrl">
<my-dir>
<button ng-click="doSomething()">Click it</button>
</my-dir>
</div>
I need to do some checks before invoking doSomething function.在调用 doSomething 函数之前,我需要做一些检查。 I can't modified anything inside my-dir directive.
我无法修改 my-dir 指令中的任何内容。 Is there a way to intercept into MyCtrl the ng-click on the button?
有没有办法拦截到 MyCtrl 上的 ng-click 按钮?
If I understand correctly,如果我理解正确,
<div ng-controller="MyCtrl">
<div ng-if = "[Function or variable] -> This can be an option to hide the button">
<my-dir>
<button ng-click="doSomething()">Click it</button>
</my-dir>
</div>
or you can override the directive but it is gonna be a bit more complex.或者您可以覆盖该指令,但它会更复杂一些。 You can check the following link, there is also a demo which can be helpful if you choose this way.
您可以查看以下链接,如果您选择这种方式,还有一个演示会有所帮助。 AngularJS override directive controller function
AngularJS 覆盖指令控制器功能
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.