Javascript Youtube视频第4版
我想在angular 4中的应用程序中插入YouTube视频 以下是html:Javascript Youtube视频第4版,javascript,angular,Javascript,Angular,我想在angular 4中的应用程序中插入YouTube视频 以下是html: <div fxFlex id="visor-video"> <iframe width="300" height="200" [src]="displayURL"> </iframe> </div> 与一般角度使用相关的几件事: -构造函数中加载的提供程序在ngOnInit()钩子
<div fxFlex id="visor-video">
<iframe width="300" height="200"
[src]="displayURL">
</iframe>
</div>
与一般角度使用相关的几件事: -构造函数中加载的提供程序在ngOnInit()钩子之前不会执行。不要试图在构造函数中使用它们。 -在这里,ngOnChanges()和sanitizedDisplayUrl()的使用是多余和无用的 关于您的问题,我将在模板中进行检查,例如:
<div
fxFlex
id="visor-video"
*ngIf=displayURL"
>
<iframe
width="300"
height="200"
[src]="displayURL"
></iframe>
</div>
与一般角度使用相关的几件事:
-构造函数中加载的提供程序在ngOnInit()钩子之前不会执行。不要试图在构造函数中使用它们。
-在这里,ngOnChanges()和sanitizedDisplayUrl()的使用是多余和无用的
关于您的问题,我将在模板中进行检查,例如:
<div
fxFlex
id="visor-video"
*ngIf=displayURL"
>
<iframe
width="300"
height="200"
[src]="displayURL"
></iframe>
</div>
您需要使用bypassSecurityTrustResourceUrl
而不是bypassSecurityTrustUrl
使用此代码-
this.displayURL = sanitizer.bypassSecurityTrustResourceUrl('https://www.youtube.com/embed/tgbNymZ7vqY');
您需要使用bypassSecurityTrustResourceUrl
而不是bypassSecurityTrustUrl
使用此代码-
this.displayURL = sanitizer.bypassSecurityTrustResourceUrl('https://www.youtube.com/embed/tgbNymZ7vqY');
*ngIf
是juse avoid error,对本用例没有任何帮助*ngIf
是juse avoid error,对本用例没有任何帮助