1

I have two different ng-app running on same page.

  1. bookingApp
  2. calendarApp

I want to share selected date scope variable from calendarApp to bookingApp. How I can achieve this functionality?

Thanks, Gladiator

2
  • do you want to say angular modules or ng-apps? Commented Apr 27, 2015 at 9:49
  • clearly mentioned ng-apps Commented Apr 28, 2015 at 3:03

2 Answers 2

1

You have to use angularjs service for this purpose.Hope the following implementation will help you to get some understanding

angular.module('app.A', [])
.service('ServiceA', function() {
    this.getValue = function() {
        return this.myValue;
    };

    this.setValue = function(newValue) {
        this.myValue = newValue;
    }
});

angular.module('app.B', ['app.A'])
.service('ServiceB', function(ServiceA) {
    this.getValue = function() {
        return ServiceA.getValue();
    };

    this.setValue = function() {
        ServiceA.setValue('New value');
    }
});
Sign up to request clarification or add additional context in comments.

2 Comments

Hi Dev, I am getting null value when I access the share variable from app.B
Are you injecting services properly ?? can you share your code
0

You can share data between Angular apps by Window postMessage and / or localStorage.

Just wrap postMessave into Angular Service and propagate changes on post event.

Comments

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.