hholtij
hholtij

Reputation: 2936

Angular 2 click on <a> does not go to link

In a component I have something like this:

<a class="btn" [attr.href]="movie.imdbUrl" target="_blank" >IMDb</a>

but when I click on it nothing happens.

movie.imdbUrl points to "http://www.imdb.com/title/tt2305051/" and I thought it would be equivalent to:

<a class="btn" href="http://www.imdb.com/title/tt2305051/" target="_blank" >IMDb</a>

What am I missing?

Upvotes: 2

Views: 4299

Answers (2)

NotBad4U
NotBad4U

Reputation: 1542

Thix example work for me :

 import { Component } from '@angular/core';

 @Component({
     selector: 'my-app',
     template: `
        <a class="btn" [attr.href]="movie.imdbUrl" target="_blank" >IMDb</a>
        `
})
export class AppComponent {
    movie = {
       imdbUrl: "http://www.imdb.com/title/tt2305051/"
    }
}

Are you sure you have defined the movie object correctly in your Component ?

Upvotes: 1

Petr Adam
Petr Adam

Reputation: 1437

Maybe not the most elegant way, but definitelly should work:

How to redirect to an external URL in Angular2

window.location.href = '...';

Upvotes: 1

Related Questions