简体   繁体   中英

angular material checkbox

I have a use case where I submit a form which in turn does a $http.get(). The get url accepts paramter say: &code ='P' &code='C'. Where P and C are to be selected from checkbox and passed to this parameter "code".

I am using angular material checkbox, but everytime I submit the form "code" parameter is getting set to true instead of P or C.

  $scope.putCall = {};
  $scope.putCall.p = 'P';
  $scope.putCall.c = 'C';

  <md-checkbox ng-model="putCall.p" aria-label="P" name="P_put_call_code">
   P: {{ putCall.p }}
  </md-checkbox>
  <md-checkbox ng-model="putCall.c" aria-label="C">
   C: {{ putCall.c }}
   </md-checkbox>

How do I pass "P" instead of true.

As in documentation :

ng-true-value The value to which the expression should be set when selected.

So in your case that would look like:

<md-checkbox ng-model="putCall.p" ng-true-value="P" ng-false-value="" aria-label="P" name="P_put_call_code">
   P: {{ putCall.p }}
</md-checkbox>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM