angular6 - angular 6显示动态html
问题描述
有人请为我澄清为什么会这样:
import { Component, OnInit } from '@angular/core';
import { InputGroup } from "../input-group";
@Component({
selector: 'app-input-group',
template: `<ul>
<li *ngFor="let input of inputs;">
<div innerHtml={{input.name}}></div>{{ input.name }},{{input.check}}
</li>
</ul>
`,
// template: '<div ng-bind-html="inputs"></div>'
})
export class InputGroupComponent implements OnInit {
public Create_Element(type: string, name: string): HTMLInputElement {
var element = document.createElement("input");
element.setAttribute("type", type);
element.setAttribute("name", name);
return element;
}
public inputs: InputGroup[] = [
{
name: this.Create_Element("text", "food1"),
check: this.Create_Element("checkbox", "food1Check")
},
{
name: this.Create_Element("text", "food2"),
check: this.Create_Element("checkbox", "food2Check")
},
{
name: this.Create_Element("text", "food3"),
check: this.Create_Element("checkbox", "food3Check")
},
];
constructor() { }
ngOnInit() {
}
}
其中“InputGroup”接口是:
export interface InputGroup {
name: HTMLInputElement,
check: HTMLInputElement
}
结果显示:
[object HTMLInputElement]
[object HTMLInputElement],[object HTMLInputElement]
[object HTMLInputElement]
[object HTMLInputElement],[object HTMLInputElement]
[object HTMLInputElement]
[object HTMLInputElement],[object HTMLInputElement]
作为我的 ul>lingfor 输出。
澄清:
我正在尝试创建 3 组输入,每组都带有文本/复选框输入,但我得到了 [object object]。
解决方案
推荐阅读
- javascript - 我的 shuffle 函数以单数形式工作,但是当将多个调用组合成一个函数时,它会中断
- scala - 当你可以使用可变类型的 val 时,为什么还要使用 var 呢?
- javascript - 如何从 Javascript 显示和生成 XML
- c# - 如何通过 API 传递三个参数并相应地检索信息
- r - 在R中提取具有同时出现的字母的单词
- c# - 如果托管在 IIS 上,ASP.NET 核心应用程序不会使用来自 RabbitMQ 队列的消息
- python - Python Pip“启动器中的致命错误”和更新 pip 的其他问题
- asp.net - 在 asp .net、IIS 8 环境中使用目录服务出现未知错误 (0x80005000)
- javascript - 在 ServiceNow 登录页面上找不到元素
- r - 在 `pkgdown` 解析参考部分的示例之前添加自定义 R 代码