Reputation: 3327
I am trying to pull json data from the angular service but its always printing blank spaces, can some one help me please. No errors in the console as well.
Service
app.service("Java4sService", function() {
var details = {};
this.details = function() {
[{
name: "James",
country: "United Stages"
}, {
name: "Rose",
country: "United Kingdom"
}, {
name: "Smith",
country: "United States"
}]
};
this.getDetails = function() {
return details;
};
});
Controller
app.controller("Java4sController",function($scope,Java4sService){
$scope.personDetails = Java4sService.getDetails();
});
Html
<ul>
<li ng-repeat="person in personDetails ">
{{person.name}} - {{person.country}}
</li>
</ul>
Upvotes: 0
Views: 150
Reputation: 1191
You should modify your service as below:
app.service("Java4sService", function() {
var details = [ {
name: "James",
country: "United Stages"
}, {
name: "Rose",
country: "United Kingdom"
}, {
name: "Smith",
country: "United States"
} ]
return {
getDetails: function() {
return details;
}
};
});
Here is the demo
Upvotes: 1