我试图从添加了bypassSecurityTrustUrl方法的控制台中删除不安全警告。但是我得到了错误
user.component.ts
import {Component,OnInit} from '@angular/core';
import { DomSanitizer } from '@angular/platform-browser';
import { NavParams,Platform,ViewController } from 'ionic-angular';
@Component({
templateUrl:`<a [href]="sanitize('sms:'+user.mobile_no)" class="anchor-default">Text</a>`,
styles:[`
.anchor-black{color: #000; font-size: 2.4rem;}
.anchor-default {text-decoration: none;}
.custom-margin{margin-left:10px;}
.anchor-right{float:right;padding-top:2px;}
.text-content{text-overflow: ellipsis; vertical-align: middle; padding-top:12px;}
`]
})
export class User implements OnInit {
public user;
public bStandings:boolean = false;
constructor(
public navParams:NavParams,
public viewCtrl:ViewController,
public platform:Platform,
public domSanitizer:DomSanitizer
) {}
sanitize(url:string){
return this.sanitizeUrl(url);
}
private sanitizeUrl(url:string):SafeUrl {
this.bStandings = true;
return this.domSanitizer.bypassSecurityTrustUrl(url);
}
}
相关问题:
Class has or is using name 'SafeUrl' from external module but cannot be named
任何人请帮助我提前谢谢
最佳答案
只需导入SafeUrl
:
import { DomSanitizer, SafeUrl } from '@angular/platform-browser';
关于javascript - 找不到名称“SafeUrl”,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/40467870/