我見過* ngFor用於從父模板重複子模板,並且也看到它在子模板本身內部使用。是否有這些情況應該被優先考慮?應該* ngFor由模板在內部使用,還是應該在外部使用?
<div class="results">
<app-result-tile
*ngFor="let d of service.data"
[data]="d">
</app-property-tile>
</div>
還是應該將ngFor移動到<app-result-tile>
組件?
<div class="results">
<app-result-tiles
[data]="service.data"> <!-- results now repeat internally with li's or something.-->
</app-result-tiles>
</div>
我將編寫一個管道來過濾來自父組件的結果組件。在這種情況下使用第一種方法會更有意義嗎?
它屬於要提供service.data或每個service.data進行處理所需的。也許你只能使用與每個service.data一起使用的子模板,因此應該使用第一種方法。 –