passing JSON data from one controller to another controller angularJS -


i want pass data 1 controller controller, getting data in $scope.imagegallerys variable , able set data setjson();

controller 1

function imagegallerycontroller($scope,$http,myservice){     var urlbase = "http://localhost:8084/apc/api/";     $http.get(urlbase + '/gallerylist').     success(function(data) {     $scope.imagegallerys = data;     myservice.setjson($scope.imagegallerys);  });     } 

i want data anther controller getjson() not returning value or object.

controller 2

    function categorycontroller($scope,myservice){     $scope.myreturn = myservice.getjson();     } 

factory

    function myservice(){       var imagegallerys = null;//the object hold our data       return{       getjson:function(){       return imagegallerys;       },       setjson:function(value){       imagegallerys = value;        }    }  angular.module('abc') .controller('categorycontroller', categorycontroller) .controller('imagegallerycontroller',imagegallerycontroller) .factory('myservice',myservice);` 

this first controller:

function imagegallerycontroller($scope,$http,myservice,$rootscope){     var urlbase = "http://localhost:8084/apc/api/";     $http.get(urlbase + '/gallerylist').     success(function(data) {     $rootscope.imagegallerys = data;     myservice.setjson($scope.imagegallerys);  });     } 

and below second controller:

function categorycontroller($scope,myservice,$rootscope){     console.log($rootscope.imagegallerys);     $scope.myreturn = myservice.getjson();     } 

i hope solution , if not please inform me


Comments

Popular posts from this blog

angular - Is it possible to get native element for formControl? -

unity3d - Rotate an object to face an opposite direction -

javascript - Why jQuery Select box change event is now working? -