[ngFor不会读取数组,如果我将其写入.ts文件中]] << [

问题描述 投票:0回答:2
这是我在search-page.component.html中调用ngFor指令的时刻:

<mat-select #orarioForm placeholder="A che ora vuoi prenotare?"> <mat-option *ngFor="let hour of availableHours">{{hour}}:00</mat-option> </mat-select>

这是search-page.component.ts中数组的声明:

export class SearchPageComponent implements OnInit { ... /* variables declaration*/ availableHours: ['08' , '09' , '10' , '11' , '12' , '13' , '14' , '15' , '16' , '17' , '18' , '19' , '20' , '21' , '22' , '23']; ... /* constructor and methods }

ngFor仅在我在指令内显式写入数组时才有效,如下所示:

<mat-select #orarioForm placeholder="A che ora vuoi prenotare?"> <mat-option *ngFor="let hour of ['08' , '09' , '10' , '11' , '12' , '13' , '14' , '15' , '16' , '17' , '18' , '19' , '20' , '21' , '22' , '23']">{{hour}}:00</mat-option> </mat-select>

但是这不是我想要的方式。我希望你能帮助我。

这是我在search-page.component.html中调用ngFor指令的时刻:

[

angular ngfor
2个回答
1
投票
© www.soinside.com 2019 - 2024. All rights reserved.