Devesh Agrawal
Devesh Agrawal

Reputation: 9212

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

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?

Upvotes: 15

Views: 32196

Answers (2)

DrKHunter
DrKHunter

Reputation: 424

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>

Upvotes: 9

Satyam Koyani
Satyam Koyani

Reputation: 4274

Use ng-href here with anchor tag.

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

You can use ng-click with this too.

Demo

Upvotes: 1

Related Questions