javascript-找不到管道’safeResourceUrl’
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了javascript-找不到管道’safeResourceUrl’,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1889字,纯文字阅读大概需要3分钟。
内容图文
![javascript-找不到管道’safeResourceUrl’](/upload/InfoBanner/zyjiaocheng/693/7f5d48585d4f4d8985b2524f247143b1.jpg)
由于我试图将youtube视频动态地嵌入到Angular 2应用中,因此正在努力解决一些安全性错误.在此处找到有关使用管道清理URL的答案.
但是遇到当前错误.
The pipe ‘safeResourceUrl’ could not be found
SafeResourceUrl.pipe.ts
import { Pipe } from '@angular/core';
import { DomSanitizer } from '@angular/platform-browser';
@Pipe({name: 'safeResourceUrl'})
export class SafeResourceUrl {
constructor(private sanitizer:DomSanitizer){}
transform(url) {
return this.sanitizer.bypassSecurityTrustResourceUrl(url);
}
}
我将其导入到我的app.module中
import { NgModule } from '@angular/core';
import { HomeModule } from './home/home.module';
import { SharedModule } from './shared/shared.module';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { SafeResourceUrl } from './shared/pipes/saferesourceurl.pipe';
@NgModule({
declarations: [
AppComponent,
SafeResourceUrl
],
imports: [
SharedModule,
HomeModule,
AppRoutingModule
]
})
并导入到我的home.component.ts中
从“ ../shared/pipes/saferesourceurl.pipe”导入{SafeResourceUrl};
home.component.html的标记
<div class="container col-lg-3 col-md-6 col-sm-12" *ngFor="let card of category.categorycards">
<div class="thumbnail">
<a href="/wiki/entity" *ngIf="card.type == 'image'">
<div class="image-wrap">
<img [src]="card.graphic" class="img-responsive" alt="[card.title]" title="[card.title]">
</div>
</a>
<a href="/wiki/category" *ngIf="card.type == 'video'">
<div class="image-wrap">
<iframe title="YouTube video player"
class="youtube-player" type="text/html"
[src]="card.url | safeResourceUrl"
height="100%" width="100%" frameborder="0"></iframe>
</div>
</a>
解决方法:
管道无法在全球范围内使用.无论它们在哪里使用,都需要将它们导入,与组件或指令相同.
@NgModule({
declarations: [
SafeResourceUrl
],
imports: [
CommonModule
]
})
class SharedModule {
@NgModule({
declarations: [
CommonModule,
HomeComponent,
],
imports: [
SharedModule,
]
})
class HomeModule
内容总结
以上是互联网集市为您收集整理的javascript-找不到管道’safeResourceUrl’全部内容,希望文章能够帮你解决javascript-找不到管道’safeResourceUrl’所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。