【问题标题】:Formly access to form control value onChange正式获取表单控件值 onChange
【发布时间】:2020-04-22 09:30:52
【问题描述】:

我正在尝试评估Formly。这是我的第一次尝试——我想在 textarea 的值发生变化时调用一个方法。这是我尝试使用的代码 - 到目前为止它似乎没有工作我不确定如果我的 templateOptions 语法错误,或者我是否应该访问不同的输入值。

 form = new FormGroup({});
  model = { defaultText: this.defaultText } ;
  label = this.defaultText ;
  fields: FormlyFieldConfig[] = [{
    key: 'editor',
    id: 'editor',
    name: 'editor',
    type: 'textarea',
    templateOptions: {
      placeholder: this.defaultText,
      onChange: this.previewText = this.parseMarkDownText(this.form.get('editor').value),
   //   appearance: 'fill'
    }
  }];

【问题讨论】:

  • 使用change fn 代替onChange

标签: angular forms material-design angular-formly


【解决方案1】:

糟糕,我忘记发布我的答案了。这是有效的。

   ngOnInit() {
        this.form = new FormGroup({});
        this.fields = [{
            key: 'editor',
            id: 'editor',
            name: 'editor',
            type: 'textarea',
            defaultValue: this.defaultText,
            templateOptions: {
                rows: 5,
                cos: 50,
                change: (field, $event)=>{ 
                    this.previewText = this.parseMarkDownText(field.form.controls.editor.value);
                },
            }
        }];
    }
    ```

【讨论】:

    猜你喜欢
    • 2016-06-10
    • 2020-05-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多