admin管理员组文章数量:1306912
If there's an ng-click and a href together on an anchor the ng-click doesn't work. I want both to work if possible, go to a route and then run a function. My use-case is I have a drawer open with a panel of links, when going to a link I want to close the drawer.
What's an easy way to get both working at the same time?
If there's an ng-click and a href together on an anchor the ng-click doesn't work. I want both to work if possible, go to a route and then run a function. My use-case is I have a drawer open with a panel of links, when going to a link I want to close the drawer.
What's an easy way to get both working at the same time?
Share Improve this question edited Sep 6, 2015 at 20:24 Gringo Suave 32k7 gold badges94 silver badges82 bronze badges asked Jul 18, 2013 at 7:20 HarryHarry 55k76 gold badges185 silver badges270 bronze badges 1- you can either redirect using href of use ng-click – Ajay Singh Beniwal Commented Jul 18, 2013 at 7:21
2 Answers
Reset to default 6Once you navigate away from the page scripts no longer run.*
Your flow can be something like:
When the user clicks, run a function that does the following:
- Run the original function you wanted to run
- Handle any 'navigate away in this specific case' logic.
- Change
location.href
to the URL you want to to navigate to.
It's of course possible to extract this behavior to a directive if you find yourself implementing that bit of logic over and over :)
* You can use onbeforeunload but that's not good for plenty of other reasons
The question was asking for the wrong thing. Using the href and the ng-click together works perfectly fine, I just had an ui-view in the parent element that prevented any angular bindings from working at all.
本文标签: javascriptangularjs ngclick and href on anchorStack Overflow
版权声明:本文标题:javascript - angularjs ng-click and href on anchor - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741828327a2399780.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论