expressionProperties属性的使用2

import {Component} from '@angular/core';
import {FormGroup} from '@angular/forms';
import {FormlyFieldConfig} from '@ngx-formly/core';

@Component({
  selector: 'app',
  template: `
    <form [formGroup]="form" (ngSubmit)="onSubmit(model)">
      <formly-form [form]="form" [fields]="fields" [model]="model"></formly-form>
      <button type="submit" class="btn btn-default">Submit</button>
    </form>
  `,
})
export class AppComponent {
  
    
  form = new FormGroup({});
  model = { email: 'email@gmail.com' };
  fields: FormlyFieldConfig[] = [
    {
      key: 'email',
      type: 'input',
      templateOptions: {
        label: 'Email address',
        placeholder: 'Enter email',
        required: true,
      },
      expressionProperties:{
          'templateOptions.disabled': model => model.itemType !== 2  // 在不等于属性为2 的情况下是 禁止的状态
      }
      
    },
     {
      key: 'email',
      type: 'select',
      templateOptions: {
        label: 'Email address',
        placeholder: 'Enter email',
        required: true,
        ngModelChange: v => {
            if(v !== 2){
                this.form.get('itemType').patchValue('D')
            }
        }
      },
     
      
    }
  ];

  onSubmit() {
    console.log(this.model);
  }
}

 

posted @ 2020-09-16 15:01  杨煊煊  阅读(173)  评论(0编辑  收藏  举报