user6440175 user6440175 - 4 months ago 10x
AngularJS Question

Angular service with parameters error

I am trying to send two variables from angular service to mvc controller. And I am getting errors all the time. Now I am getting the error that compName doesn't exist. I have been stacked for a few hour, I tried to debug it with the angular debugger but no luck so far.
I think that my error has something to do with the angular controller is trying to call the service on load instead on click, but I don't know how to fix that.

myApp.service('getDocTypesService', ['$http', '$q', function ($http, $q) {
var allSettings = null;
this.getDocTypes = function (compName, custName) {
var def = $q.defer()
if (allSettings) {
} else {
$'GetDocTypes', { companyName: compName, customerName: custName })
.then(function (response) {
var response = $.parseJSON(
allSettings = response;
return def.promise;

This is my angular controller and the service:

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



This is the HTML:

<select ng-model = "selectedDocument" ng-click="getDocTypes(selectedCompany, enteredCustomer)">
<option>Select document</option>
<option ng-repeat="docSetting in docSettings" value=" {{docSetting.Doc_Type}}">{{docSetting.Doc_Type}}</option>


Try this:


$scope.getTypes = function(comp, cust) {
    getDocTypesService.getDocTypes(comp, cust).then(function (value) {
          $scope.docSettings = value


<select ng-model = "selectedDocument" ng-click="getTypes(selectedCompany, enteredCustomer)">

Obs: selectedCompany and enteredCustomer must be $scope variables defined before the click happens.