Hi guys, I manage to save data from http get request to factory, Now I want to save multiple/array of data to the factory and call it to other controllers. How can I save an array or multiple of data to the factory? Thanks… By the way this is my code: Pretty much new to Ionic and AngularJS
.factory(‘Data’, function () {
var user = {};
return {
getUser: function () {
return user;
},
setUser: function (userparameter) {
user = userparameter;
}
};
})
.controller(‘LoginCtrl’, function ($scope, $http, $state, $ionicModal, Data) {
$scope.details = {};
$scope.getData = function () {
$http.get("http://localhost/colombiandreamdate/v1/userlogin", { params: { username: $scope.details.username, password: $scope.details.password } })
.success(function (data) {
Data.setUser(data.id);
$scope.id = data.id;
$scope.username = data.username;
$scope.role = data.role;
$scope.date_created = data.date_created;
$state.go('lounge');
})
.error(function (data) {
alert("Something Went Wrong");
});
}
})
.controller(‘LoungeCtrl’, function ($scope, Data) {
$scope.user = Data.getUser();
})