如何将地址或任何字段复制到 angular-formly 中的另一个字段?
How to copy address or any fields to another fields in angular-formly?
我想弄清楚当用户单击复选框时如何将主电子邮件复制到备用电子邮件。我正在使用 angular 的 angular-formly
指令。我陷入了这个小实现。
这是Plunkr
如有任何帮助,我们将不胜感激。
最简单的方法是在复选框上添加监视,然后将备用电子邮件设置为电子邮件地址。
$scope.formFields = [
{
"key": "firstName",
"type": "text",
"label": "First Name",
"placeholder": "Jane",
"required":true
},{
"key": "email",
"type": "email",
"label" :"Primary Email",
"placeholder": "janedoe@gmail.com",
"required":true
},
{
"key": "altEmail", // you need a unique key for this one
"type": "email",
"label":"Alternate Email",
"placeholder": "janedoe@gmail.com",
"required":true,
ngModelAttrs: {
myCustomValue: {
bound: 'email',
attribute: 'email'
}
},
templateOptions: {
myCustomValue: "email"
}
},
// ...
$scope.$watch('result.sameAsPrimary', function(newValue) {
if (newValue) {
$scope.result.altEmail = $scope.result.email;
}
});
我想弄清楚当用户单击复选框时如何将主电子邮件复制到备用电子邮件。我正在使用 angular 的 angular-formly
指令。我陷入了这个小实现。
这是Plunkr
如有任何帮助,我们将不胜感激。
最简单的方法是在复选框上添加监视,然后将备用电子邮件设置为电子邮件地址。
$scope.formFields = [
{
"key": "firstName",
"type": "text",
"label": "First Name",
"placeholder": "Jane",
"required":true
},{
"key": "email",
"type": "email",
"label" :"Primary Email",
"placeholder": "janedoe@gmail.com",
"required":true
},
{
"key": "altEmail", // you need a unique key for this one
"type": "email",
"label":"Alternate Email",
"placeholder": "janedoe@gmail.com",
"required":true,
ngModelAttrs: {
myCustomValue: {
bound: 'email',
attribute: 'email'
}
},
templateOptions: {
myCustomValue: "email"
}
},
// ...
$scope.$watch('result.sameAsPrimary', function(newValue) {
if (newValue) {
$scope.result.altEmail = $scope.result.email;
}
});