zoukankan      html  css  js  c++  java
  • 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);
      }
    }
  • 相关阅读:
    CSS3 not
    rxjs1
    Angular 2 组件之间如何通信?
    开发去。。
    补零补零
    MySQL数据库从复制及企业配置实践
    互联网中接口安全解决方案
    redis服务打不开--解决办法
    搭建Git服务器
    git将当前分支上修改的东西转移到新建分支
  • 原文地址:https://www.cnblogs.com/yangxuanxuan/p/13679161.html
Copyright © 2011-2022 走看看