i have two scopes (arrays). One with room data and one with room list. So everytime a user want to add some data for each room have to select it from a dropdown (select option) and add that data he wants. Now, i need to exclude every room tat already have some data from the dropdown and i am trying like thi.
Here is the Room list:
$scope.propertyRooms = [
{
id: "1",
name: "Room 1 Sea View"
},
{
id: "2",
name: "Room 2 Mountain View"
},
{
id: "3",
name: "Room 3"
}
];
Here is the room with data (to exclude):
$scope.ratePlansRoomsSettings = [
{
id: "1",
name: "Room 1 Sea View",
allotment: "10",
minPax: "1",
maxPax: "5",
maxAdult: "5",
maxChild: "4",
maxInf: "1",
childAllowed: true
},
{
id: "2",
name: "Room 2 Mountain View",
allotment: "10",
minPax: "1",
maxPax: "10",
maxAdult: "10",
maxChild: "8",
maxInf: "1",
childAllowed: false
}
];
Here is how i am trying to exclude the selected:
$scope.getAvailableRooms = function(){
var selectedRooms = [];
for(i = 0; i < $scope.propertyRooms.length; i++){
var found = false;
for(j = 0; j < $scope.ratePlansRoomsSettings.length; j++){
if($scope.ratePlansRoomsSettings[j].id == $scope.propertyRooms[i].id){
found = true;
break;
}
}
if(!found){
selectedRooms.push($scope.propertyRooms[i]);
}
return $scope.propertyRooms;
}
}
here is the select options:
<select ng-model="room.name" ng-options="p.name as p.name for p in getAvailableRooms()" ng-hide="room.name" class="form-control"></select>
The problem is that the select options give me all the time all the rooms from the propertyRooms scope instead those only that are not selected.
I am not receiving any errors but i beleive i am wrong in the for function.
selectedRoomsinstead of the unfiltered$scope.propertyRooms?