Click here to Skip to main content
15,881,380 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi ,
I want to share the data between controllers through factory

JavaScript
SApp.factory('commonservice', function ($http) {
    var loginuserDetails = {} ;

    var addItemFunction =  function(item) {
          loginuserDetails = item;
    };
    var getListFunction =  function() {
        return loginuserDetails;
    };

      return {
        post: function (dataObj, serviceMethod) {
           return $http.post(serviceUrl + '/' + serviceMethod, dataObj);
          },
        addItem: addItemFunction,
        getList: getListFunction    

    }
});
 commonservice.addItem($scope.LoginDetailsModel);when accessing it
$scope.LoginDetailsModel = commonservice.getList();
Getting undefined

What I have tried:

I have tried it through factory . if there are other way through which I can share the data , then do let me know
Posted
Updated 13-Apr-17 1:54am
v2
Comments
sajeetharan 13-Apr-17 14:30pm    
Post your controller code
Bohdan Stupak 21-Jul-17 3:30am    
looks pretty decent except you're creating service via factory and share code in your service. did you provide a reference to your service in controller like SApp.controller('yourController', function($scope, commonservice //more codes

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900