ng-hrefDirectiva AngularJS


Ejemplo

Haz un href usando AngularJS:

<div ng-init="myVar = 'https://www.w3schools.com'">
    <h1>Tutorials</h1>
    <p>Go to <a ng-href="{{myVar}}">{{myVar}}</a> to learn!</p>
</div>

Definición y uso

La ng-hrefdirectiva anula el atributo href original de un elemento <a>.

La ng-hrefdirectiva debe usarse en lugar de href si tiene código AngularJS dentro del valor href.

La ng-hrefdirectiva se asegura de que el enlace no se rompa incluso si el usuario hace clic en el enlace antes de que AngularJS haya evaluado el código.


Sintaxis

<a ng-href="string"></a>

Compatible con el elemento <a>.


Valores paramétricos

Value Description
string A string value, or an expression resulting in a string.