Get function
Closed this issue · 1 comments
I have modified this program.
i want to get all users who logged in and to display that users in html page.
In service.js
i have used
function register(username, password ,firstname) {
$http.get('/user/register')
.success(function(data) {
$scope.users = data;
console.log(data);
})
.error(function(data) {
console.log('Error: ' + data);
});
error is coming like
Error: $scope is undefined
register/<@http://localhost:3000/services.js:101:4
m/h.success/<@http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.9/angular.min.js:87:164
f/<@http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.9/angular.min.js:119:221
$eval@http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.9/angular.min.js:133:442
$digest@http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.9/angular.min.js:131:33
$apply@http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.9/angular.min.js:134:234
g@http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.9/angular.min.js:88:1
R@http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.9/angular.min.js:92:116
Zf/</v.onload@http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.9/angular.min.js:93:155
You should not be messing with scope inside a service. Return the users from the function and, then, when you call the function inside of the controller, assign the results to the scope.
I am closing this issue since this question is beyond the scope of the blog post and code.
Please either ask this question on the comments part of the blog or on Stack Overflow.