Function combination javascript

0

Hello, I have two functions that work separately very well, but I need to combine them now to organize the result of the other. Organs Function:

$scope.$watch('organ_id', function (newValue, oldValue) {
    if (newValue != null && newValue != '') {
       $scope.servicesPromise =
          $http
            .get('/api/services.json?organ_id=' + newValue)
              .success(function (data) {
                $scope.total_pages = data.total_pages;
                $scope.services = data.services;
            });
        };
    }, true);

Function by letters

$scope.byLetter = function (letter) {
      $scope.servicesPromise =
          $http
            .get('/api/services.json?letter=' + letter)
              .success(function (data) {
                    $scope.total_pages = data.total_pages;
                    $scope.services = data.services;
            $scope.tama_letra = data.tam_letter;
                });
    };

The function of organs brings a set and what I want is that when I select the order by letters the return is only the services of that given organ with that letter.

For example: If I chose organ X; I have returned SX services; in this set I want to know what services I initial with the letter E; I choose the letter E; I need the answer, in this case, the SX starting with E.

    
asked by anonymous 14.09.2017 / 19:27

1 answer

0

You can make the request with two parameters:

function _search(organ_id, letter) {
  var params = {};

  params.organ_id = organ_id;
  params.letter = letter;

  return $http.get('/api/services.json', {params: params}).success(function(data) {
    $scope.total_pages = data.total_pages;
    $scope.services = data.services;
  });
}
    
14.09.2017 / 19:43