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?
AngularJS ng-href Directive 1 Definition and Usage. The ng-href directive overrides the original href attribute of an <a> element. ... 2 Syntax. Supported by the <a> element. 3 Parameter Values. A string value, or an expression resulting in a string.
Introduction to AngularJs onclick AngularJS ng-click is an In-Built AngularJS directive that is mainly used to handle the click events on the HTML view and processing the data in the controller as per requirements. The ng-click directive can be used with multiple HTML elements such as button, input, select, checkbox, etc.
Definition and Usage The ng-href directive overrides the original href attribute of an <a> element. The ng-href directive should be used instead of href if you have AngularJS code inside the href value. The ng-href directive makes sure the link is not broken even if the user clicks the link before AngularJS has evaluated the code.
is wrong. What is actually happening is that after your click, the click event is first handled by angular (defined by ng-click directive in angular 1.x and click in angular 2.x+) and then it continues to propagate (which eventually triggers the browser to navigate to the url defined with href attribute).
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>
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With