0

I have this code

function GuestWizardController($scope, ApiResourceBed, ApiResourceRoom) {
        $scope.rooms = ApiResourceRoom.query();
        $scope.showBeds = function( roomId ){
            $scope.beds = ApiResourceBed.query();
        };
        var vm = this;
        vm.data = {}
    }

ApiResourceBed and ApiResourceRoom are two factories.

I need a select element with all rooms listed. So far, so good.

The thing is that, when I select a room, it triggers showBeds function. Now, I need a way to filter the beds array. So, in a second select element, I can present only the beds asociated to the selected room.

I'm quite new to angular. Any ideas?


UPDATE

ApiResourceBed factory declaration:

.factory('ApiResourceBed', ['APP', '$resource', function( APP, $resource, id ){
    return $resource( APP.API_REST + 'beds/:id');
}])
3
  • Show the $resource configuration for ApiResourceBed. You pass roomId to your function but not to $resource Commented Oct 28, 2015 at 19:47
  • have you seen my answer? Commented Oct 30, 2015 at 19:13
  • Solved it via backend. Added some extra lines in order to get only the beds I need. I'll check out later your answer. Sure it helps in another part of the app Commented Oct 31, 2015 at 16:12

1 Answer 1

1

Here it is an old answer (answered by me) in which I built 2 custom filters for filtering a select input.

2 multiple select and single option list

A different solution could be to filter the options by the selected room, but that depends on your room object, and we need some more info. This could be an example:

<select ng-model="selectedRoom" ng-options="room for room in rooms"></select>

<select ng-model="selectedBed" ng-options="bed for bed in selectedRoom.beds"></select>
Sign up to request clarification or add additional context in comments.

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.