【问题标题】:Cannot find name 'SafeUrl'找不到名称“SafeUrl”
【发布时间】:2016-11-07 23:31:42
【问题描述】:

我正在尝试从添加了 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

请大家帮帮我提前谢谢

【问题讨论】:

  • 为什么需要清理user.mobile_no

标签: javascript html angular ionic2


【解决方案1】:

也只需导入SafeUrl

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

【讨论】:

    猜你喜欢
    • 2016-01-24
    • 1970-01-01
    • 2021-10-29
    • 2019-11-17
    • 2018-03-27
    • 2017-08-01
    • 2018-06-28
    • 2021-06-23
    相关资源
    最近更新 更多