单击按钮即可正式更新templateOptions [英] Formly update templateOptions on click of button

查看:82
本文介绍了单击按钮即可正式更新templateOptions的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是正式的新手,我想根据值更改templateOptions属性,所以下面是我的配置

I'm new to formly, I want to change the templateOptions property based on value, so below is my config

 formlyConfig.setType({
      name: 'phone',
      extends: 'maskedInput',
      defaultOptions: {

       templateOptions: {
          mask: '999-9999-9999'
        },

我要在单击按钮时将蒙版更改为"999-999-9999",

I want to change the mask to mask: '999-999-9999' on a button click,

我试图在按钮的onclick上执行此操作,但是没有变化

I tried to do this on onclick of button , but no change

                 formlyConfig.setType({
                    name: 'phone',
                    defaultOptions:{
                      templateOptions: {
                        mask: '999-999-9999'
                      },
                    }                     
                  })

;

推荐答案

我正在考虑您正在使用角形.在这里,我认为您不能随时更改配置选项.因此,您必须从DOM&中删除该字段.然后使用新的配置选项(例如mask)重新加载它.因此,您可以单击任意按钮来调用method,在其中可以重置一些布尔标志&然后更新配置选项&然后设置标志.

I'm considering you're using angular-formly. Here I don't think you can change config options on the go. So, to do that you've to delete the field from DOM & then reload it with new config option (e.g. mask). So, you can call method on click of any button, in which you can reset some boolean flag & then update config option & then set the flag.

<button class="btn" ng-click="vm.clickFn()">click</button>

clickFn可以位于哪里:

Where clickFn can be:

vm.clickFn = function() {
   vm.show = false;
   vm.fields[0].templateOptions.mask = "999-999-9999";
   $timeout(function() {
     vm.show = true;
   });
}

这里的超时时间只是让它更新标志&的一小段时间.运行摘要循环.

Here timemout is just a small time to let it update the flag & run digest cycle.

示例 进行引用.

Example to refer.

这篇关于单击按钮即可正式更新templateOptions的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆