I am not getting the array of customers back from the angular service.
Service:
surchargeIndex.service('customerService', [
"$http", function ($http) {
this.get = function (customerType) {
if (customerType == "1") {
getProduction().then(function (result) { return result.data; });
} else if (customerType == "2") {
getTest().then(function (result) { return result.data; });
} else {
getAll().then(function (result) { return result.data; });
}
}
var getTest = function () {
return $http({
method: "GET",
url: "api/Customer/GetTest",
})
.success(function (data) {
return data;
});
};
var getProduction = function () {
return $http({
method: "GET",
url: "api/Customer/GetProduction",
})
.success(function (data) {
return data;
});
};
var getAll = function () {
return $http({
method: "GET",
url: "api/Customer/GetAll",
})
.success(function (data) {
return data;
});
};
Controller Call:
$scope.getCustomers = function(customerType) {
$scope.showContent = false;
$scope.customers = customerService.get(customerType);
};
HTML:
<div ng-controller="CustomerController" data-ng-init="init()" class="col-md-2">
<select ng-model="customerKey" ng-options="customer.Key as customer.Value for customer in customers"></select>
</div>
The call is being made to the server every time; however, the select list isn't being populated.
getProduction(),getTest()andgetAll()so we can see what you are returning? If you are wanting to return fromthis.get()then you can just return the $http method and chain onto itreturn $http().then()..... something().then().then()thenhandler.