Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.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
Html Angular 2在div标记中获取json数据_Html_Json_Angular - Fatal编程技术网

Html Angular 2在div标记中获取json数据

Html Angular 2在div标记中获取json数据,html,json,angular,Html,Json,Angular,我是Angular 2的新手,使用json数据,在使用typescript处理时,我使用{{data | json}}从对象获取json数据,而不是json变量,我需要在网页上的标记中获取数据。是否有可用的解决方案 例如:如果数据采用以下格式: { type:"header",subtype:"h1",name:"FormName" } <h1>Form Name</h1> 我需要以下格式的文件: { type:"header",subtype:"h1",name:

我是Angular 2的新手,使用json数据,在使用typescript处理时,我使用
{{data | json}}
从对象获取json数据,而不是json变量,我需要在网页上的
标记中获取数据。是否有可用的解决方案

例如:如果数据采用以下格式:

{ type:"header",subtype:"h1",name:"FormName" } 
<h1>Form Name</h1>
我需要以下格式的文件:

{ type:"header",subtype:"h1",name:"FormName" } 
<h1>Form Name</h1>
表单名称

如果我完全理解您的问题,您可以在Angular2中使用innerHtml函数

app.component.ts

export class AppComponent implements {
constructor() {
}

data = { type:"header",subtype:"h1",name:"Formname" };
  htmlString=`<${this.data.subtype}>${this.data.name</${this.data.subtype}>`;}
导出类AppComponent实现{
构造函数(){
}
数据={type:“header”,subtype:“h1”,name:“Formname”};
htmlString=`${this.data.name`;}
app.component.html

<div [innerHTML]="htmlString"></div>

如果我完全理解您的问题,您可以在Angular2中使用innerHtml函数

app.component.ts

export class AppComponent implements {
constructor() {
}

data = { type:"header",subtype:"h1",name:"Formname" };
  htmlString=`<${this.data.subtype}>${this.data.name</${this.data.subtype}>`;}
导出类AppComponent实现{
构造函数(){
}
数据={type:“header”,subtype:“h1”,name:“Formname”};
htmlString=`${this.data.name`;}
app.component.html

<div [innerHTML]="htmlString"></div>

假设您从服务中检索整个表单的内容,将其作为一个对象数组,每个对象都有一个元素。 使用
*ngFor(arr的obj)
var元素=“{obj.value}}”
formElement.append(元素)


(这只是一个存根来说明。这将创建所有类型的元素,您只需处理不同类型的属性,如css)

假设您从服务中以对象数组的形式检索整个表单的内容,每个对象都有一个元素。 使用
*ngFor(arr的obj)
var元素=“{obj.value}}”
formElement.append(元素)


(这只是一个存根来说明。这将创建所有类型的元素,您只需处理不同类型的属性,如css)

{{data.name}
?你的问题很不清楚。我认为他需要在HTML标记中获取该子类型并在其中命名。我有10组不同的json数据,我需要将它们与相关的div与该数据匹配,我使用的标记是文本、数字、日期、标题等,
{data.name}
?你的问题很不清楚。我认为他需要在HTML标记中获取该子类型,并在其中包含名称。我有10组不同的json数据,我需要将它们与相关的div与该数据进行匹配,我使用的标记是文本、数字、日期、标题等。,