I am having a strange problem where when i add a single line of code the app doesn't work after a refresh Here is my controller :
myApp.controller('messengernew', ['$scope', '$resource', 'AuthService', '$location', '$http', 'User','Message', function ($scope, $resource, AuthService, $location, $http, User, Message) {
$scope.users=[];
$scope.messages=[];
User.getAllUsers().then(function(users) {
$scope.users = users;
for (var i = 0; i < users.length; i++) {
(function(user){
console.log('username ' + user.username);
// User.incrementReputation(user.username);
Message.getUnreadMessages(user.username, localStorage.getItem("token")).then(function(messages) {
$scope.messages.push(messages);
})
})(users[i]);
}
})
$scope.username=localStorage.getItem("token");
$scope.gotomessages = function (text) {
var contact =text;
localStorage.setItem("contact", contact);
$location.path('/messenger');
};
}]);
If i uncomment User.incrementReputation(user.username)
the app doesn't work after a refresh can you help ?
And the function incrementReputation is in a service and here is the code :
function incrementReputation(username) {
getUser(username).then(function(users) {
(function(user){
$http.put('/api/incrementReputation', {}, {params:{id:user._id}});
})(users[0]);
})
}
and the function getUser also in a service (the same as incrementReputation )) :
function getUser(username) {
var Users = $resource('/api/users', {},{
query: {method: 'get', isArray: true}
});
return Users.query({username:username}).$promise
}
Shot in the dark with the given information. May be a semicolon issue in the getUser function.
return Users.query({username:username}).$promise;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.