Angular HTML绑定不起作用

时间:2018-08-15 10:17:41

标签: javascript angular

我正在尝试遍历数组并创建可以正常工作但 string filepath = "data/data/[package-name]/files/[name-of-db]"; 无法正常工作的DOM。我遵循了这个example,但是在这里也无法使用。

这是json

    string filepath = "data/data/com.foo.foo/files/localstorage.db";

    var bytes = System.IO.File.ReadAllBytes(filepath);
    var fileCopyName = string.Format("/sdcard/Database_{0:dd-MM-yyyy_HH-mm-ss-tt}.db", System.DateTime.Now);
    System.IO.File.WriteAllBytes(fileCopyName, bytes);

HTML

pipe

自定义管道

[{
  "question":"What is this in QUestiom?",
  "ans":"<strong> this </strong> is only question"

},{
  "question":"What is the output of following code ?",
  "ans":"vgvfvfg"
},{
  "question":"What is the output of following code ?",
  "ans":"fcfcff"
}]

这是DEMO的工作对象。我期望 <div *ngFor="let ques of questionseries;let i =index" class="test"> <div> <span [innerHTML]="ques.question | safeHTML"> </span> </div> <div>{{ques.ans}}</div> </div> 将在import { Pipe, PipeTransform } from '@angular/core'; import {DomSanitizer} from "@angular/platform-browser"; @Pipe({ name: 'safeHTML', pure:false }) export class SafeHTMLPipe implements PipeTransform { constructor(private sanitizer:DomSanitizer){} transform(value: any, args?: any): any { console.log(value , args); return this.sanitizer.bypassSecurityTrustHtml(value); } } 内,但只能正确渲染。

1 个答案:

答案 0 :(得分:3)

该行也需要绑定到innerHTML:

0

如下所示:

  <div>{{ques.ans}}</div>