我的班级中有一个角度素材选择绑定到appraisalPeriod
变量:
<md-select placeholder="Select Appraisal Period" class="custom-select" id="appraisalPeriod" name="appraisalPeriod" [(ngModel)]="appraisalPeriod" (ngModelChange)="onApprisalChange($event)" floatPlaceholder="never">
<md-option *ngFor="let period of appraisalPeriodList | keys" [value]="period.key">{{period.value}}</md-option>
</md-select>
期间的一个例子:{“201707”:“2017Q2”}
我的.ts
文件中有一个发射器:
this.emitterGoalsheet.subscribe(goalSheet => {
this.appraisalPeriod = goalSheet.appraisal_id;
alert(this.appraisalPeriod);
});
但是,当提取appraisalPeriod
属性时(如显示的警告框所示),选择框值不会自行更新并保持为空。
其他信息:
keys.pipe.ts
档案:
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({ name: 'keys'})
export class KeysPipe implements PipeTransform {
transform(value: any, args: string[]): any {
const keys = [];
for ( const key in value ) {
if (value.hasOwnProperty(key)) {
keys.push({key: key, value: value[key]});
}
}
return keys;
}
}