2

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?

hholtij
  • 2,906
  • 6
  • 27
  • 42

2 Answers2

1

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

How to redirect to an external URL in Angular2

window.location.href = '...';
Community
  • 1
  • 1
Petr Adam
  • 1,425
  • 11
  • 23
1

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 ?

NotBad4U
  • 1,502
  • 1
  • 16
  • 23
  • I did but I also had a typo in an id attribute which read "movie" as well. That confused Angular. Can't say I blame it. Thanks to everybody who responded. – hholtij Jun 19 '16 at 10:44