如果我将数组写入 .ts 文件,ngFor 不会读取它
ngFor doesn't read the array if I write it on the .ts file
这是我在搜索中调用 ngFor 指令的时刻-page.component.html :
<mat-select #orarioForm placeholder="A che ora vuoi prenotare?">
<mat-option *ngFor="let hour of availableHours">{{hour}}:00</mat-option>
</mat-select>
这是搜索中数组的声明-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>
但这不是我想要的工作方式。
我希望你能帮助我。
您需要用 =
,
分配值
availableHours = ['08' , '09' , '10' , '11' , '12' , '13' , '14' , '15' , '16' , '17' , '18' , '19' , '20' , '21' , '22' , '23'];
:用于打字,
= 它的评估
这是我在搜索中调用 ngFor 指令的时刻-page.component.html :
<mat-select #orarioForm placeholder="A che ora vuoi prenotare?">
<mat-option *ngFor="let hour of availableHours">{{hour}}:00</mat-option>
</mat-select>
这是搜索中数组的声明-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>
但这不是我想要的工作方式。 我希望你能帮助我。
您需要用 =
,
availableHours = ['08' , '09' , '10' , '11' , '12' , '13' , '14' , '15' , '16' , '17' , '18' , '19' , '20' , '21' , '22' , '23'];
:用于打字, = 它的评估