我对 Angular 很陌生,我试图将 html 文件作为我的字符串插入并插入到 DIV 元素中
我有我的search.component.html电话
<div #ID></div>
Run Code Online (Sandbox Code Playgroud)
组件.ts
import { Component} from '@angular/core';
@Component({
selector: 'app-search',
templateUrl: './search.component.html',
styleUrls: ['./search.component.scss']
})
export class SearchComponent {
constructor() {}
let ServerResponseHtml = '<div><input type="text"/><input type="text"/><span class="btn btn-outline-primary btn-sm" (click)="open(content)">View Document</span></div>';
document.getElementById("DIV").innerHTML = ServerResponseHtml;
}
Run Code Online (Sandbox Code Playgroud)
我从服务器获取响应作为完整的 html 标记,我只需要附加到我的 DOM 中并显示内容,标记也可以具有内联样式。
我试过了,<div [innerHTML]="ServerResponseHtml"></div> and <div innerHTML="{{ServerResponseHtml}}"></div>但这不是显示为 html,而是显示为文本。