1

I have days option for user.

My expected output will be, when a user click submit

  • if monday and tuesday is selected it should be [1,2]
  • if weekdays is selected it should be string 'weekdays'

I have too many restriction here because the api is heavily nested so I prefer to hardcode the days value. But I don't know how to proceed further. The only way I can think of is assign ng-model to every input and do push, but I feel that's not proper.

http://plnkr.co/edit/NfTgmsuZlGh6QUVZj8HG?p=preview

Need help.

2

2 Answers 2

1

You can try in this way also In Controller

  $scope.items = [{"day":"monday","show":"1"},{"day":"tuesday","show":"2"},{"day":"weekdays","show":"weekdays"}];

in html

<select ng-model="selection" ng-options="item.show as item.day for item in items">
     <option value="">Please select</option>
</select>

output: {{selection}}

Sign up to request clarification or add additional context in comments.

Comments

0

Try this way:

<div class="days-group" ng-repeat="timeType in timeTypes">
    <input type="checkbox" id="Weekdays" value="weekdays" ng-model="timeType.isSelected" ng-checked="timeType.isSelected">
    <label for="Weekdays">{{timeType.type}}</label>
</div>

And controller:

$scope.timeTypes = [
                    { id: 1, type: "weekends", isSelected: false }, 
                    { id: 2, type: "weekdays", isSelected: false }
                   ];

Same for days also.

Check working jsfiddle link:

https://jsfiddle.net/avnesh2/oho7qxv1/

Check console for required format.

Cheers.

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.