ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

angular-formly中 expressionProperties 属性的使用方式:

2020-09-16 15:03:30  阅读:11  来源: 互联网

标签:formly templateOptions required angular expressionProperties email


参考网址:https://formly.dev/guide/getting-started

 

expressionProperties 属性的使用方式:
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 {
    // 是否保存为草稿 状态
    isRequired = 'true'
    
  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.required': () => this.isRequired  // 不是为草稿状态下 是必填字段
      }
      
    },
     {
      key: 'email',
      type: 'input',
      templateOptions: {
        label: 'Email address',
        placeholder: 'Enter email',
        required: true,
      },
      expressionProperties:{
          'templateOptions.required': () => this.isRequired  // 不是为草稿状态下 是必填字段
      }
      
    }
  ];

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

  

标签:formly,templateOptions,required,angular,expressionProperties,email
来源: https://www.cnblogs.com/yangxuanxuan/p/13679141.html

专注分享技术,共同学习,共同进步。侵权联系[admin#icode9.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有