我是 Angular 的新手。我从版本开始。 2.
我需要链接到file://...
网址。
我试过正常href
:
Note: app
是处理应用程序的网络模型对象。
<a target="_blank" href="file://{{app.outputPath}}/index.html">no link here</a>.
这是行不通的——链接在那里,URL 正确,但 Angular 似乎以某种方式阻止了该事件。为什么?
所以我见过ng-href
但这是针对 Angular 1.x 的。和没有*ngHref https://angular.io/docs/js/latest/api/#!?apiType=Directive据我所知。所以这只是一个天真的尝试:
<a target="_blank" *ngHref="file://{{app.outputPath}}/index.html">over a directive</a>.
我还看到了一些带有路由的内容,但似乎仅适用于应用程序内的内部链接:
<a [router-link]="['/staticReport', {path: app.outputPath}]">see the report</a>.
app.component.ts:
@RouteConfig([
...
{path:"/staticReport/:path", redirectTo: 'file:// ???? ' }
])
创建外部链接的方法是什么?
我假设app
被分配为异步。您可以使用以下方法解决此问题埃尔维斯操作员 https://en.wikipedia.org/wiki/Elvis_operator:
<a target="_blank" href="file://{{app?.outputPath}}/index.html">no link here</a>.
当 Angular 之前尝试解析绑定时,不要破坏绑定app
实际上有一个价值。
Original例如,这有效:
@Component({
selector: 'my-app',
template: `
<h2>Hello {{name}}</h2>
<a target="_blank" [href]="'file://' + outputPath + '/index.html'">no link here</a>
`
})
export class App {
outputPath:string = 'www.google.com';
constructor() {
this.name = 'Angular2';
}
}
Plunker https://plnkr.co/edit/IvTzuJ?p=preview
实际上,你的第一个例子也很好用
<a target="_blank" href="file://{{outputPath}}/index.html">no link here</a>
Plunker https://plnkr.co/edit/pamdfw?p=preview
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)