目前正在学习 Angular5 课程,并且在对该主题进行了一段时间的研究之后,我仍然不完全理解以下内容:
代码:
App.component.html:
<app-server-element
*ngFor="let serverElement of serverElements"
[element]="serverElement"
></app-server-element>
App.component.ts:
import { Component } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
serverElements = [{type: 'server', name:'Testserver',content:'just a test!'},
{type: 'server', name:'Testserver',content:'just a test!'}
];
}
服务器-element.component.html:
<p>
<strong *ngIf="element.type === 'server'" style="color: red">
{{ element.content }}</strong>
<em *ngIf="element.type === 'blueprint'">{{ element.content }}</em>
</p>
服务器-element.component.ts:
import { Component, OnInit,Input } from '@angular/core';
@Component({
selector: 'app-server-element',
templateUrl: './server-element.component.html',
styleUrls: ['./server-element.component.css']
})
export class ServerElementComponent implements OnInit {
@Input() element: {type:string, name:string, content:string};
}
问题:
我有点困惑这部分的作用:
*ngFor="let serverElement of serverElements"
[element]="serverElement"
在我目前的理解中,它是一个循环遍历 serverElementsArray 的所有元素的 for 循环。但是[element]="serverElement"
具体做什么呢?