如何以角度形式从字段传递数据?

时间:2016-06-16 20:39:39

标签: angularjs 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是一个复选框,点击后会显示短片选择选项....如果选中短片,我怎么能传递一个值?

e.g。可以说一件衬衫的价格是10美元,我希望在检查短裤时价格增加5美元。我怎么能做到这一点?

1 个答案:

答案 0 :(得分:0)

这可以通过在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
                  }
              }
            },