[英]How do I pass data from a field in angular formly?
所以我有这些领域
vm.prepFields = [
{
key: 'shirt',
type: 'select',
templateOptions: {
label: 'Choose Shirt Size',
placeholder: 'Select option',
options: shirt_list
}
},
{
key: 'shortsq',
type: 'checkbox',
templateOptions: {
label: 'Shorts',
}
},
{
key: 'shorts',
type: 'select',
templateOptions: {
label: 'Choose Shorts Size',
options: shorts_list
}, expressionProperties: {
hide: '!model.shortsq'
}
}
];
}
shortsq是一个复选框,单击该复选框会显示短裤选择选项。...如果选中了短裤,如何传递值?
例如,假设一件衬衫的价格为10美元,我希望在检查短裤时该价格增加5美元。 我该怎么做?
这可以通过使用templateOptions中的onChange轻松完成:
{
key: 'shortsq',
type: 'checkbox',
templateOptions: {
label: 'Shorts',
onChange: function($viewValue, $modelValue, $scope) {
if($scope.model.shortsq) $scope.model.shirtPrice += 5; //increase price by $5 when checked
else $scope.model.shirtPrice -= 5; //reduce price by $5 when not checked
}
}
},
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.