pass more than one variable in angularjs? -
app.factory('datapassingservice', function() { var saveddata = {}; function set(data) { saveddata = data; } function get() { return saveddata; } return { set: set, get: } });
controller1
$scope.text = '9'; datapassingservice.set($scope.text);
controller2
$scope.mes = datapassingservice.get(); alert("the scope "+scope.mes);
i pass $scope.text controller1 controller 2 using app.factory , work perfect. pass more scopes controller1 controller2 example pass $scope.text='9' , scope.text1='10' , take controller2 datapassingservice.get().thanks in advance
you pass in key uniquely identify each different piece of data, example:
app.factory('datapassingservice', function() { var saveddata = {}; function set(key, data) { saveddata[key] = data; } function get(key) { return saveddata[key]; } return { set: set, get: } });
usage:
controller 1
$scope.text = '9'; datapassingservice.set("mykey", $scope.text); datapassingservice.set("message", "foo");
controller 2
$scope.mes = datapassingservice.get("mykey"); $scope.message = datapassingservice.get("message"); alert("the scope " + $scope.mes); // scope 9
Comments
Post a Comment