0

firstapp

 var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope, $http) {
$http.get("welcome.htm").then(function (response) {
    $scope.myWelcome = response.data;
});
});

sencond app

 var app = angular.module('myApp2', []);
app.controller('myCtrl2', function($scope, $http) {
$http.get("fsd.htm").then(function (response) {
    $scope.myWelcome = response.data;
});
});

How to Pass data from one app to another app in angularjs ?

8
  • can you please send some examples@DhavalMarthak Commented Feb 16, 2018 at 12:18
  • @selvakumar why do you need two apps? Commented Feb 16, 2018 at 12:19
  • 4
    Possible duplicate of Is it possible to share data between two angularjs apps? Commented Feb 16, 2018 at 12:21
  • let me try bro @AlekseySolovey Commented Feb 16, 2018 at 12:24
  • 1
    @selvakumar can you inject one module into another: angular.module('myApp', ['myApp2']); ? There shouldn't be any reason for you to have multiple apps Commented Feb 16, 2018 at 15:09

2 Answers 2

2

You can use shared service to communicate between two angular apps. However using multiple apps is not a good practice unless it is the only option left.

angular.module('sharedService', []).factory('SharedService', function() {
  var SharedService;
  SharedService = (function() {
    function SharedService() {}
    SharedService.prototype.setData = function(name, data) {};
    return SharedService;
})();
  if (typeof(window.angularSS) === 'undefined' || window.angularSS === null) {
    window.angularSS = new SharedService();
  }
  return window.angularSS;});
  angular.module("angularApp1", ['sharedService'])
    /*code */
  angular.module("angularApp2", ['sharedService'])
    /*code */
Sign up to request clarification or add additional context in comments.

Comments

0
        Create function like this in Service Lyaer
        editTool: function(yourData) {
                        var basicAuth = YOurauthenticateFuntion;
                        var url =  'url';
                        var deferred = $q.defer();
                        $http.post(url, yourData, {
                            headers: {
                                'Content-Type': 'application/json',
                                'Accept': 'application/json',
                                'Authorization': basicAuth 
                            }
                        }).then(function(data) {
                            if(data.status == 200) {
                            deferred.resolve(data.data);
                            } else {
                                deferred.reject(data);
                            }
                        }, function(error) {
                            deferred.reject(error);
                        });
                        return deferred.promise;
                    }
    and then can call in any controller using factory name.. that you have created for serviceCalls

1 Comment

don't use $q and $http together, $http already returns a promise that can resolve your response / data

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.