首页 > 解决方案 > 绑定角度形式选择选项不起作用

问题描述

我正在尝试使用以下代码正式绑定选择类型选项:

      fieldGroup: [
    {
      key: 'TimeOffTypeID',
      type: 'select',
      className: 'flex-40 padding-10',
      templateOptions: {
        label: 'نوع مرخصی',
        placeholder: 'نوع مرخصی',
        required: true,
        options: this.getTimeoffType,
        valueProp: 'TimeOffTypeID',
        labelProp: 'TimeOffTypeName',
      },

    types$: BehaviorSubject<any[]> = new BehaviorSubject<any[]>([]);
     
    public get getTimeoffType(): Observable<any[]> {

    return this.types$.asObservable();
    }

和数据服务

      getTimeoffTypes() {

this.base
  .get(
    Controller.TIMEOFFTYPE,
    {
      TimeOffTypeID: 0,
    },
    Actions.SEARCH
  )
  .subscribe(({ result }) => {
    console.log(result)
    this.types$.next(result);
    
  })

}

结果有我的数据,但此数据未绑定到表单选择选项

标签: angulartypescriptbehaviorsubjectangular-formly

解决方案


我遇到了同样的问题,没有显示选项。下面突出显示的代码有助于解决它;templateOptions : { label : "Gender.", labelProp : "name", valueProp : "value", options : [ { "name" : "Male", "value" : "male" }, { "name" : "Female ", "value" : "female" }, { "name" : "Others", "value" : "others" } ],注意:我使用的是 Formly Material


推荐阅读