Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular2:呈现Html受信任字符&;时代周刊,;复制_Html_Angularjs_Angular - Fatal编程技术网

Angular2:呈现Html受信任字符&;时代周刊,;复制

Angular2:呈现Html受信任字符&;时代周刊,;复制,html,angularjs,angular,Html,Angularjs,Angular,在组件模板中渲染&次时,我遇到了一个问题 @Component({ selector:'my-app', template:` <div> <input [(ngModel)]="toDoModel" type="text"> <button (click)="onClickToDo(toDoModel)">Click me</button> <ul> <

在组件模板中渲染&次时,我遇到了一个问题

@Component({
    selector:'my-app',
    template:`
    <div>
    <input [(ngModel)]="toDoModel" type="text">
    <button (click)="onClickToDo(toDoModel)">Click me</button>      
    <ul>
        <li *ngFor="let item of todoList; let i = index">{{item}}
          <a (click)="remove(i)">&times</a>
        </li>
    </ul>
    </div>`
})
@组件({
选择器:'my-app',
模板:`
点击我
    {{item} &时代
` })
您可以使用DomainSanitationService正确解析
&时间,如下所示

演示

从'@angular/platform browser'导入{domsanizationservice};
@组成部分({
选择器:'my-app',
模板:`
点击我
    {{item}
` }) 导出类AppComponent{ 危险URL=“×”; 构造函数(sanitizer:DomSanitizationService){ this.myHTML=sanitizer.bypassSecurityTrustHtml(this.dangerousUrl); } }
或 正如@rinukkusu所建议的

<a (click)="remove(i)">&times;</a>
×;

您可以使用DomainSanitationService正确解析
&时间,如下所示

演示

从'@angular/platform browser'导入{domsanizationservice};
@组成部分({
选择器:'my-app',
模板:`
点击我
    {{item}
` }) 导出类AppComponent{ 危险URL=“×”; 构造函数(sanitizer:DomSanitizationService){ this.myHTML=sanitizer.bypassSecurityTrustHtml(this.dangerousUrl); } }
或 正如@rinukkusu所建议的

<a (click)="remove(i)">&times;</a>
×;

看起来你忘了放
序列末尾的字符

以下内容将成功渲染:

例如用法


看起来你忘了放
序列末尾的字符

以下内容将成功渲染:

例如用法


对于那些对angular 2.0.0(发行版)中的DomainSanitizationService感兴趣的人,它已被重命名为DomainSanitizer

import { Component, OnInit } from '@angular/core';
import { DomSanitizer, SafeHtml } from '@angular/platform-browser';

@Component({
    selector: 'app-root',
    templateUrl: './app.component.html',
    styleUrls: ['./app.component.scss']
})
export class AppComponent implements OnInit {
    public someSafeHtml: SafeHtml;

    constructor(
        private _domSanitizer: DomSanitizer) {
    }

    ngOnInit() {
        this.someSafeHtml = this._domSanitizer.bypassSecurityTrustHtml('&copy; Example.com');
    }
}

对于那些对angular 2.0.0(发行版)中的DomainSanitizationService感兴趣的人,它已被重命名为DomainSanitizer

import { Component, OnInit } from '@angular/core';
import { DomSanitizer, SafeHtml } from '@angular/platform-browser';

@Component({
    selector: 'app-root',
    templateUrl: './app.component.html',
    styleUrls: ['./app.component.scss']
})
export class AppComponent implements OnInit {
    public someSafeHtml: SafeHtml;

    constructor(
        private _domSanitizer: DomSanitizer) {
    }

    ngOnInit() {
        this.someSafeHtml = this._domSanitizer.bypassSecurityTrustHtml('&copy; Example.com');
    }
}


问题是什么?它呈现为“×”文本。您是否尝试过
×
?@rinukkusu是对的。你只需要一个分号@rinukkusu感谢它为我工作有什么问题吗?它呈现为“×”文本。您尝试过
×
?@rinukkusu是对的。你只需要一个分号@rinukkusu感谢它为mecan工作。您给出了需要DomsanizationService的任何其他示例吗?要动态生成html控件,请使用它。例如,复选框。如果要使用
DOMSanizationService
,请不要忘记提供
BROWSER\u SANITIZATION\u PROVIDERS
。仅仅提供
domsanizationservice
是行不通的。请检查我的plunker@rinukkusu。我的意思是我认为这不是必需的。这很好。您能给出其他需要DomsanizationService的例子吗?要动态生成html控件,请使用ca。例如,复选框。如果要使用
DOMSanizationService
,请不要忘记提供
BROWSER\u SANITIZATION\u PROVIDERS
。仅仅提供
domsanizationservice
是行不通的。请检查我的plunker@rinukkusu。我的意思是我认为这不是必需的。拥有它很好。