导出在下拉列表中不具有约束力的常量值
export const values not binding in dropdown
我在单独的文件中有一个常量值,并在下拉选项中绑定值,工作日工作正常但间隔时间将其绑定为对象对象
这是 constantvalues.ts
它工作正常
export const weekdays =['sunday','Monday','Tuesday','wednesday','thursday'];
不工作
export const IntervalTime =[{key:0,value:'10.00'},{key:1,value:'11.00'}];
component.ts
import {Component,OnInit} from '@angular/core';
import {weekdays} from './constantvalues';
/**
* @title Basic select
*/
@Component({
selector: 'select-overview-example',
templateUrl: 'select-overview-example.html',
styleUrls: ['select-overview-example.css'],
})
export class SelectOverviewExample implements OnInit {
days=[];
//not working[![enter image description here][1]][1]
times =[];
ngOnInit(){
[...this.days] = weekdays;
[...this.times]=IntervalTime;
}
}
html:
<mat-form-field>
<mat-select placeholder="select Weekdays">
<mat-option *ngFor="let day of days" [value]="day">
{{day}}
</mat-option>
</mat-select>
</mat-form-field>
<hr/> Second Dropdrown with Array of object
<mat-form-field>
<mat-select placeholder="select Weekdays">
<mat-option *ngFor="let time of times" [value]="time">
{{time}}
</mat-option>
</mat-select>
</mat-form-field>
对于时间,您应该分配 time.value
,而不是整个对象
<mat-form-field>
<mat-select placeholder="select Weekdays">
<mat-option *ngFor="let time of times" [value]="time">
{{time.value}}
</mat-option>
</mat-select>
</mat-form-field>
分叉 demo
我在单独的文件中有一个常量值,并在下拉选项中绑定值,工作日工作正常但间隔时间将其绑定为对象对象 这是 constantvalues.ts
它工作正常
export const weekdays =['sunday','Monday','Tuesday','wednesday','thursday'];
不工作
export const IntervalTime =[{key:0,value:'10.00'},{key:1,value:'11.00'}];
component.ts
import {Component,OnInit} from '@angular/core';
import {weekdays} from './constantvalues';
/**
* @title Basic select
*/
@Component({
selector: 'select-overview-example',
templateUrl: 'select-overview-example.html',
styleUrls: ['select-overview-example.css'],
})
export class SelectOverviewExample implements OnInit {
days=[];
//not working[![enter image description here][1]][1]
times =[];
ngOnInit(){
[...this.days] = weekdays;
[...this.times]=IntervalTime;
}
}
html:
<mat-form-field>
<mat-select placeholder="select Weekdays">
<mat-option *ngFor="let day of days" [value]="day">
{{day}}
</mat-option>
</mat-select>
</mat-form-field>
<hr/> Second Dropdrown with Array of object
<mat-form-field>
<mat-select placeholder="select Weekdays">
<mat-option *ngFor="let time of times" [value]="time">
{{time}}
</mat-option>
</mat-select>
</mat-form-field>
对于时间,您应该分配 time.value
,而不是整个对象
<mat-form-field>
<mat-select placeholder="select Weekdays">
<mat-option *ngFor="let time of times" [value]="time">
{{time.value}}
</mat-option>
</mat-select>
</mat-form-field>
分叉 demo