I have been developing a simple AngularJS App. I need to implement a custom service named 'countryservice' for it. Following is my code.
var countryApp = angular.module('countryApp', []);
countryApp.service('countryservice', function ($http) {
this.getallcountries = function ($http) {
$http.get('js/countries.json').success(function (data) {
return data;
});
}
});
countryApp.controller('CountryCtrl', function ($http, $scope, countryservice) {
$scope.countries = countryservice.getallcountries($http);
});
Unfortunately this code doesn't work for some reason. But cannot figure out why. When I do the same thing without creating my own custom service it works fine. Following is the code without implementing a custom service. This one works fine.
var countryApp = angular.module('countryApp', []);
countryApp.controller('CountryCtrl', function ($scope, $http) {
$http.get('js/countries.json').success(function (data) {
$scope.countries = data;
});
});
Can anybody help me with what I'm doing wrong with my custom service?