我试图弄清楚当用户单击复选框时如何将主电子邮件复制到备用电子邮件。我正在使用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;
}
});