Quantcast
Channel: Ionic Framework - Ionic Forum
Viewing all articles
Browse latest Browse all 49164

Store Multiple Data to Factory

$
0
0

@anicacute09 wrote:

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();

})

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 49164

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>