3

I would like to use ng-value="true" and false (boolean) for a select option. But I want to fill the options in php because I am using laravel and the translator. This is my code, and the value is not boolean after I send the form.

 <select
      id="job-payed"
      required
      class="form-control"
      name="payed"
      ng-model="payed">
  <option selected disabled value>Please choose..</option>
  <option ng-value="true">Payed</option>
  <option ng-value="false">Not payed</option>
 </select>
4
  • i know that i could use an js array, and use ng-options. but i want to fill it in php. ng-options="opt as opt.label for opt in options" Commented May 9, 2016 at 14:23
  • It will be a string going to your controller. Your controller needs to convert it to a boolean. Commented May 9, 2016 at 14:50
  • You can use "value" instead of "ng-value". Then use strings 'payed'/'notpayed' in your logic. Commented May 9, 2016 at 14:51
  • hm, yeah you are right. and there is no way to solve this in a other way? Commented May 9, 2016 at 14:54

3 Answers 3

2

if someone still gets that problem, try this :

<select id="job-payed" required class="form-control" name="payed" ng-model="payed">
    <option selected disabled value>Please choose..</option>
    <option ng-value="{{ true }}">Payed</option>
    <option ng-value="{{ false }}">Not payed</option>
</select>
Sign up to request clarification or add additional context in comments.

Comments

0

Try to use ng-value="'true'" because ngValue should contain an expression to the value of

If you use ng-value="true" angular will look for variable called true in your scope($scope.true)

See https://docs.angularjs.org/api/ng/directive/ngValue

Comments

0

This works on select boxes as expected starting in Angular 1.6.0. Prior versions' ng-value treat the values as Strings in select boxes.

Angular 1.5.0: https://plnkr.co/edit/G52M9yaAgJjfVj82i3YF?p=preview

Angular 1.6.0: https://plnkr.co/edit/nyI4ENLW1h0z3JuyDYWO?p=preview

Update the version in the plunk to see how the types change:

<script src="//code.angularjs.org/1.5.0/angular.min.js"></script>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.