0

I need idea on how to create a app structure of two separate Angularjs App folder.

Let's say:

In my XAMPP/htdocs, I have a separate folder of Angularjs App folder. The A app folder and the B app folder need to integrate(I don't know if it is the right term) to each other.

Example, there's a SignIn in A app folder, when the credentials is valid, it will redirect to B app folder, when Signout in B app folder, user will be redirected to A app folder.. something like that..

My question is, How I can connect that two (A and B app folder)?

I hoped I discussed it well enough to understand. Thanks.

1 Answer 1

1

You can use services to achieve this objective. As you have two different apps and you need to create a bridge between them, a good way is to create services that can be injected where you need them. A AngularJs service is created inside an AngularJs App, by declaring it using your angular module like this:

angular.module("YourAngularModuleName").factory("MyCustomService",
[
   "injectedDependency",
   function(injectedDependency)
   {
       var serviceInstance={};

       serviceInstance.operationYouNeed = function(){
            //do your stuff.
            return;
       };

       return serviceInstance;
   }
]);

This service above is a example structure of a service called "MyCustomService" that has a method called "operationYouNeed".

On your AngularJs App controller, you can inject your MyCustomService and call operationYouNeed as you may need it.

Considering the scenario you exposed, I don't know the way you are keeping the logged user context, but you can evaluate the user action on the service method and then call a $location.path("your app2 root url") in order to redirect the user or, if is the case, call a $window.location.href = "your app2 root url" in order to cause a page reload.

In applications that I write, I use to implement a token based authentication and store the temporary toke as a private cookie, so if I had your app scenario, on App2 I would inject $cookies on my Service and use it to retrieve the temporary cookie in order to check session validation and also decide if I need to redirect my user or not.

Another kind of concept you can implement here is to use a third AngularJs app in which you declare your common service, so you don't need to create any dangerous circular reference between your two apps.

I don't know the deepnes of your AngularJs knowledge but you allways need to declare a module dependency whe you does something like this, by including it on your AngularJs app module, like so:

angular.module("YourAngularModuleName",["anotherDepencyModule", "another", ...]);

Hope it helps. Cheers.

Sign up to request clarification or add additional context in comments.

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.