Can we have both href and ng-click in Angular.js

Devesh Agrawal picture Devesh Agrawal · Apr 8, 2015 · Viewed 31.3k times · Source

I have a text box:

<input type="text" ng-model="SearchText" >

And a link:

<a href="#signout" ng-click="SearchText=''">Sign out</a>

I want to exectue both in the above hyperlink. ng-click to empty text-box and #signout will ng-route to signout HTML and controller.

But I can see href overrides ng-click in Angular.js

How to execute both?

Answer

DrKHunter picture DrKHunter · Dec 9, 2016

If you use ng-mouseup or ng-mousedown depending on when you need the event to fire it will not override ng-href like ng-click does.

<a ng-href="#signout" ng-mouseup="SearchText=''">Sign out</a>