在组件模板中渲染& times 时,我遇到了问题。
@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)">×</a>
</li>
</ul>
</div>`
})
答案 0 :(得分:2)
答案 1 :(得分:2)
对于那些对角度2.0.0(发布版)中的 DomSanitizationService 感兴趣的人 - 它已被重命名为 DomSanitizer 。
Timestamp.valueOf(String)
答案 2 :(得分:1)
您可以使用 DomSanitizationService 正确解析×
,如下所示,
DEMO :https://plnkr.co/edit/4X2vINBbXmaJ0eHZ9ZZX?p=preview
import {DomSanitizationService} from '@angular/platform-browser';
@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)" [innerHTML]="myHTML"></a>
</li>
</ul>
</div>`
})
export class AppComponent{
dangerousUrl='<span>×</span>';
constructor(sanitizer: DomSanitizationService) {
this.myHTML= sanitizer.bypassSecurityTrustHtml(this.dangerousUrl);
}
}
正如@rinukkusu建议的那样,
<a (click)="remove(i)">×</a>