How can I force ng-click to take precedence over an ng-blur event?

筅森魡賤 提交于 2019-11-30 07:50:58
Uli Köhler

Instead of ng-click, use ng-mousedown. Mousedown events get fired before blur events.

However, the handled mousedown might un-focus your field without the blur event being fired. If you then click outside the box, the blur event won't be fired (because the field is already blurred), so after setting focus, you might need to re-focus the field manually - see How to set focus on input field?

Note that by using this approach, the button can also be triggered using right-click (thanks Alexandros Vellis!) as you can see in this official example.

6220119

Don't use ng-blur then, bind the $document with click event to stop edit mode. And remember to unbind the event when the scope is destroyed.

If you want to run click event functionality before ng-blur than write your functionality in ng-mousedown event instead ng-click.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!