2016-06-16 3 views
1

Я использую эту услугу, чтобы получить данные json. Как я могу передать два параметра. С json мне нужно заполнить выпадающее меню.Параметры углового прохода и прием json

 myApp.service('allCurrentSettingsService', ['$http', '$q', function ($http, $q) { 
     var allSettings = null; 
     this.getList = function() { 
      var def = $q.defer() 
      if (allSettings) { 
       def.resolve(allSettings); 
      } else { 
       $http.post('GetAllCurrentSettings', { companyName: compName, customerName: custName }) 
        .then(function (response) { 
         var response = $.parseJSON(response.data) 
         allSettings = response; 
         def.resolve(allSettings); 
        }); 
      } 
      return def.promise; 
     } 
    }]); 

И вот я звоню службу:

myApp.controller('myController', ['$scope', 'getDocTypesService', 
    function ($scope, getDocTypesService) { 
    $scope.getDocTypes = ''; 
    getDocTypesService.getList(compName, custName).then(function (value) { 
    $scope.getDocTypes = value 
    }); 
} 

]);

+0

Где бы вы хотели добавить параметры? Запрос? Url params? тело? – mfrachet

+0

- это два параметра, идущих от углового к вашему обслуживанию или от вашего обслуживания до углового? – Manatax

+0

Спасибо. Параметры идут от углового обслуживания к моему контроллеру mvc. – user6440175

ответ

1

Вы пропустили параметры функции. Пожалуйста, добавьте то же самое в определение функции.

this.getList = function (compName, custName) { 
 
      var def = $q.defer() 
 
      if (allSettings) { 
 
       def.resolve(allSettings); 
 
      } else { 
 
       $http.post('GetAllCurrentSettings', { companyName: compName, customerName: custName }) 
 
        .then(function (response) { 
 
         var response = $.parseJSON(response.data) 
 
         allSettings = response; 
 
         def.resolve(allSettings); 
 
        }); 
 
      } 
 
      return def.promise; 
 
     }

Вы можете назвать $ http.post() другими способами также:

var data = {param:'val1',.....} 
 
    $http({ 
 
    url: "time.php", 
 
    method: "POST", 
 
    params: data 
 
    })

+0

Я пробовал это (см. Обновленный файл), но не работал. – user6440175

+0

. Проверьте обновленный ответ. – Aravind

+0

Спасибо. Не могли бы вы показать мне, как добавлять эти параметры при вызове службы, я добавил код. – user6440175

Смежные вопросы