Angular-Formly:隐藏时重置字段模型

时间:2015-11-17 00:53:17

标签: angular-formly

使用Angular Formly,我使​​用'hideExpression'来隐藏基于另一个字段的模型值的字段。这按预期工作。但是,当隐藏字段模型值变为隐藏时,我需要重置它。如何以Angular-Formly完成?我可以挂钩吗?

3 个答案:

答案 0 :(得分:1)

你可以使用hideExpression回调并在返回true或false之前设置模型值

{
            key: 'model_key',
            type: 'input',
            templateOptions: {
                label: 'Your label'
            },
            hideExpression: function ($viewValue, $modelValue, scope) {
                var hide = true; // replace true with your condition
                if (hide) {
                     vm.model.model_key = '';
                }
                return hide;
            }
        }

答案 1 :(得分:0)

约翰。我也与这个问题作斗争。我意识到,与其使用正式示例中的模型,不如使用 form.value 。这将从模型中删除所有隐藏字段。-

答案 2 :(得分:0)

在指向 JS Bin 的链接中改用范围,例如

hideExpression: function ($viewValue, $modelValue, scope) {
  var hide = !scope.model.name;
  if (hide) {
    vm.model.iLikeTwix = false;
  }
  return hide;
}
相关问题