正式访问表单控制值onChange

正式访问表单控制值onChange

本文介绍了正式访问表单控制值onChange的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试评估形式.这是我的第一次尝试-当textarea的值更改时,我想调用一个方法.这是我尝试过的代码-到目前为止,它似乎没有起作用,我不确定我的templateOptions语法是否错误,或者我是否应该访问不同的输入值.

I'm trying to evaluate Formly. This is my first attempt - I want to call a method when the value of a textarea change. This is the code I tried with - so far it doesn't appear to be working I'm not sure If my syntax for the templateOptions is wrong or if I should be accessing the value of the input different.

 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'
    }
  }];

推荐答案

糟糕,我忘记发布答案了.这是行得通的.

Oops, I forgot to post my answer. This is what worked.

   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);
                },
            }
        }];
    }
    ```

这篇关于正式访问表单控制值onChange的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 11:22