This code is used to fetch the data from my web api, but it does not work. I have checked again and again, but noting happened. please help me, whether I hand a wrong code?
var MyApp = angular.module("MyApp", []);
MyApp.factory('Service', ['$http', function ($http) {
var urlBase = 'http://localhost:1883/api';
var datafactory = {};
Service.getCustomers = function () {
return $http.get(urlBase + '/Customers1');
};
return datafactory;
}]);
MyApp.Controller('UpdateController', ['$scope', 'datafactory', function ($scope, datafactory) {
getCustomers();
function getCustomers() {
datafactory.getCustomers()
.then(function (data) {
$scope.customers = data;
}, function (error) {
$scope.status = 'Unable to load customer data: ' + error.message;
});
}
}]);
here is the error from browser: enter image description here
There is a typo, you return an empty object. Change Service.getCustomers
to datafactory.getCustomers
.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments