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/“,我认为这相当于:
<a class="btn" href="http://www.imdb.com/title/tt2305051/" target="_blank" >IMDb</a>
我错过了什么?
答案 0 :(得分:1)
也许不是最优雅的方式,但definitelly应该有效:
How to redirect to an external URL in Angular2
window.location.href = '...';
答案 1 :(得分:1)
Thix示例工作对我来说:
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/"
}
}
您确定在Component中正确定义了影片对象吗?