Templating with href in angular (4)

AngularJS required that you use ng-href because there were issues with binding expressions to some types of DOM elements and attributes.

This problem doesn’t exist in Angular now.

The following will work as expected:

<a href="{{your expression here}}"></a>

You can also bind using the attr prefix like this:

<a [attr.href]="your expression here"></a>

As others have mentioned. If you are using routing and want to add a href attribute to a specific route. Use the routerLink directive as it will add the href attribute to <a> tags.

Leave a Comment