I am looking to store form values in JSON
to send via $http.post. One of the values, rooms
, should be an array with a length determined by the selected value from md-select
. The value of Adult
should be included within each room entry.
var data = {
rooms: [{
adults: this.adultsHotels,
}]
This is how my rooms should appear in the view:
<md-select ng-model="rooms" name="numberOfRooms" ng-required="true">
<md-option ng-repeat="roomsHotel in roomsHotel"
ng-model="roomsHotel"
ng-selected = "$first"
ng-value="roomsHotel.number"
ng-messages>
{{roomsHotel.number}}
</md-option>
</md-select>
The controller for rooms is as follows:
$scope.roomsHotel = ('1 2 3 4 5').split(' ').map(function(roomsHotel) {
return {number: roomsHotel};
});
The view for selecting number of adults is shown below:
<md-select ng-model="adultsHotels" name="numberOfAdults" ng-required="true">
<md-option ng-repeat="adultsHotel in adultsHotel"
ng-model="adultsHotel"
value="{{adultsHotel.number}}"
ng-messages>
{{adultsHotel.number}}
</md-option>
</md-select>
Note: The objective is to dynamically add rooms based on selection and specify the number of adults in each. Appreciate any assistance.
"rooms": [
{
"adults": "1"
},
{
"adults": "2"
}
]