找不到名字' SafeUrl'

时间:2016-11-07 14:42:28

标签: javascript html5 angular ionic2

我正在尝试从控制台中删除不安全警告我添加了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

任何人都请提前帮助我

1 个答案:

答案 0 :(得分:5)

只需导入SafeUrl

import { DomSanitizer, SafeUrl } from '@angular/platform-browser';