angular移除模板文件中的链接前缀“unsafe”

作者: wxfeng 分类: 未分类 发布时间: 2017-08-10 00:00    阅读 1,215 次


Use the DomSanitizer:

import {DomSanitizer} from '@angular/platform-browser';
...
constructor(private sanitizer:DomSanitizer){}
...
let sanitizedUrl = this.sanitizer.bypassSecurityTrustUrl('Notes://MYSERVER/C1256D3B004057E8');

or create a method to return the sanitized url:

sanitize(url:string){
    return this.sanitizer.bypassSecurityTrustUrl(url);
}

and then in your template:

<[href]="sanitize('Notes://MYSERVER/C1256D3B004057E8')" ..

如果觉得我的文章对您有用,请随意赞赏。您的支持将鼓励我继续创作!

发表评论

您的电子邮箱地址不会被公开。

烂笔头