Hi all,
I have a code:
app.factory("serviceDashboard", ['$http', function ($http) {
var obj = {};
obj.getMessages = function (username) {
$http.get(serviceBase + 'Dashboard/GetMessages/', {
params: { username: username, }
}).then(function (data) {
return data;
});
}
return obj;
}])
app.controller('dashboard', function ($scope, $rootScope,
serviceDepartment, $http, serviceDashboard) {
$scope.loadMessages = function () {
var username = $rootScope.globals.currentUser.username;
serviceDashboard.getMessages(username).then(function (data) {
$scope.messages = data.data;
});
}
$scope.loadMessages();
});
When i run it will display error "cannot read property 'then' of undefined".
But when i change code in factory to :
obj.getMessages = function (username) {
return $http.get(serviceBase + 'Dashboard/GetMessages/', {
params: { username: username, }
});
}
It works. I am newbie. Pls explain for me. Thanks.
--
You received this message because you are subscribed to the Google Groups
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.