在我的component.html文件中有以下代码
<button mat-flat-button class="mat-flat-button mat-accent ng-star-inserted" color="accent" (click)="playVideo(video)">
<mat-icon [svgIcon]="video.type === 'external' ? 'open-in-new' : 'play-arrow'"></mat-icon>
<span class="alfadown">Open Video</span>
</button>
和component.ts文件下的这段代码
public playVideo(video: Video) {
if (video.type === 'external') {
window.open(video.url, '_blank');
} else {
this.store.dispatch(new PlayVideo(video, this.mediaItem));
}
}
我想要的是插入在外部链接,这个固定的网址在前面的(video.url) https://example.com/abc/123.php
假设(video.url)生成的链接为http://youtube.com/xyz ,则完整链接应为
https://example.com/abc/123.php?http://youtube.com/xyz
我如何在angular 7中做到这一点。
发布于 2019-03-12 04:41:13
如果它是一个没有逻辑的固定字符串,你可以将这些字符串连接起来。
public playVideo(video: Video) {
const prefix = "https://example.com/abc/123.php?";
if (video.type === 'external') {
window.open(prefix + video.url, '_blank');
} else {
this.store.dispatch(new PlayVideo(video, this.mediaItem));
}
}
https://stackoverflow.com/questions/55109883
复制相似问题