数据循环
- *ngFor 普通循环 eg: *ngFor="let item of listArray"
- template 循环数据 eg:template="ngFor let item of listArray"
home.component.ts
public:list=[];
public:list3:any[];
constructor(){
this.list=['数学','语文','外语'];
this.list3 = [
{'name','小明','text','我喜欢数学'},
{'name','小红','text','我喜欢数学'},
{'name','小花','text','我喜欢数学'},
]
}
home.component.html
<ul>
<li *ngFor="let item of list;let key=index">
{{item}}--{{key}}
</li>
</ul>
<ul>
<li template="ngFor let item of list;let key=index">
{{item}}--{{key}}
</li>
</ul>
<ul>
<li *ngFor="let item of list2;let key=index">
{{item.name}}--{{item.titl}}---{{key}}
</li>
</ul>
声明属性的几种方式
- public 共有*默认,可以在这个类里边使用,也可以在类外边使用
- protected 保护类型,他只有在当前类和他的子类里边可以访问
- private 私有,只有在当前类才可以访问这个属性