Angular-Formly:隐藏时重置字段模型
Angular-Formly: Reset Field Model When Hidden
使用Angular 形式上,我使用'hideExpression' 根据另一个字段的模型值隐藏一个字段。这按预期工作。但是,当它隐藏时,我需要重置隐藏字段模型值。如何在 Angular-Formly 中实现?有什么类型的活动我可以挂钩吗?
您可以使用 hideExpression 回调并在 return 之前设置模型值 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;
}
}
在 JS Bin 的 link 中使用作用域,例如
hideExpression: function ($viewValue, $modelValue, scope) {
var hide = !scope.model.name;
if (hide) {
vm.model.iLikeTwix = false;
}
return hide;
}
使用Angular 形式上,我使用'hideExpression' 根据另一个字段的模型值隐藏一个字段。这按预期工作。但是,当它隐藏时,我需要重置隐藏字段模型值。如何在 Angular-Formly 中实现?有什么类型的活动我可以挂钩吗?
您可以使用 hideExpression 回调并在 return 之前设置模型值 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;
}
}
在 JS Bin 的 link 中使用作用域,例如
hideExpression: function ($viewValue, $modelValue, scope) {
var hide = !scope.model.name;
if (hide) {
vm.model.iLikeTwix = false;
}
return hide;
}