【发布时间】:2021-03-23 05:17:13
【问题描述】:
我有一个带有一些 ul 和 li 的简单 html 视图。但是我需要在代码中使用数组'jsonarray'得到与ngfor相同的结构。下面是https://stackblitz.com/edit/angular-eigvsq?file=src%2Fapp%2Fapp.component.ts
的代码app.component.html
<div>
<ul>
<h5>Red</h5>
<li>1</li>
<li>2</li>
<li>3</li>
<h5>Blue</h5>
<li>4</li>
<li>5</li>
<li>6</li>
</ul>
</div>
app.component.ts
import { Component, OnInit } from "@angular/core";
@Component({
selector: "my-app",
templateUrl: "./app.component.html",
styleUrls: ["./app.component.css"]
})
export class AppComponent {
name = "Angular";
jsonarray = {
id: "0001",
Red: [
{ id: "1001", Order: 1 },
{ id: "1002", Order: 2 },
{ id: "1003", Order: 3 }
],
Blue: [
{ id: "5001", Order: 4 },
{ id: "5002", Order: 5 },
{ id: "5005", Order: 6 }
]
};
ngOnInit() {}
}
【问题讨论】:
-
如果你知道你需要
ngFor,那你为什么不用ngFor来写呢?或者,你想让别人为你写这篇文章吗?
标签: javascript angular