I created a factory service called siteCollection:
spApp.factory('siteCollection', function(){
return {
usersObject : [],
getUsers : function (){
$().SPServices({
operation: "GetUserCollectionFromSite",
completefunc: function(xData, Status) {
var responseXML = $(xData.responseXML);
responseXML.find("User").each(function() {
usersObject.push({
id: $(this).attr("ID"),
name: $(this).attr("Name"),
domainAccount: $(this).attr("LoginName")
});
});
}
});
return usersObject;
}
}
})
The intention is to return the usersObject that I defined at the beginning, but I'm encountering an undefined error in the console for the object.
Below is the controller code:
spApp.controller('userCtrl',
function userCtrl($scope,siteCollection){
$scope.users = siteCollection.getUsers();
}
);
I am still learning Angular and navigating through the challenges.