我的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)前面的FIXED URL插入外部链接 https://example.com/abc/123.php?
假定,(视频.url)生成的链接为http://youtube.com/xyz。完整链接应为:
https://example.com/abc/123.php?http://youtube.com/xyz
我该如何在角度7中做到这一点?
答案 0 :(得分:1)
如果它是没有逻辑的固定字符串,则可以串联这些字符串。
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));
}
}