I've used both href
and ng-href
and I couldn't see the difference between them.
Why does Angular have the ng-href
attribute, and when should I use it?
I've used both href
and ng-href
and I couldn't see the difference between them.
Why does Angular have the ng-href
attribute, and when should I use it?
If you need to bind values from your model you use the directive. For example:
In the example above, the value of
address
is programmatically bound to the value in the input text box, which you can change.If you don't need to be dynamic (i.e. react to a change in the model's state), then you can simply stay with
href
:From the documentation:
Effectively, the only place you're using it is for links in which you need to rely on a value provided to the DOM by Angular. If you do not require Angular for a part of that link, or you don't plan on using Angular to generate that link, then you do not need to use
ngHref
.