0

Angular module is defined as :

angular.module('module1',['ngRoute']);

Route for module1 is defined as

 module1.config(function($routeProvider) 
 {
      $routeProvider
      .when('/Application1',
       {
            templateUrl: 'Application1/Application1_HomePage.html',
       })         
      .otherwise({
          templateUrl: 'MainPage.html',
          controller: 'ctrl'
      )}
 });

And the controller ctrl is defined as:

 module1.controller('ctrl',function($scope,$location)
 {
         $scope.goToApp1 = function()
         {
              $location.path('/Application1',true);
         }
 });

The shell page is as :

<html ng-app="module1">
   <body>
      <div ng-view>   </div>                   
   </body>
</html>

Application1_HomePage.html contains another ng-app than the shell page ng-app module1.

From the shell page shown above, when a call to Application1_HomePage.html is made through routeProvider, initialization of ng-app written inside Application1_HomePage.html is failing. The browser inspector clearly shows nothing out of the DOM.

Considering the above scenario how can I make a navigation from one ng-app to another ng-app?

1 Answers1

0

Assuming both of the modules have an entrance page you can just put a link to the other app page, for example:

you load module1Index.html and on that page you put an link to module2Index.html:

<a href="http://module2.com"></a>

If you need both modules to sit on the same page , just include one in the other:

angular.module('module1', ['module2']);
Tomer
  • 17,787
  • 15
  • 78
  • 137
  • Am new to angular. _If_ the OP _could_ (re)move the `ng-app` from `html` and say scope each to their own `div`, wouldn't that also be an option? – EdSF Jan 13 '16 at 16:22
  • @EdSF - you have to tell angular what is the app module, either by defining ng-app, or by initializing it through JS. – Tomer Jan 13 '16 at 16:24
  • Understood, so `
    ` and another `
    ` each with their own areas of responsibility (instead of scoping the entire thing in one app because `ng-app` was defined in the top level ``)?
    – EdSF Jan 13 '16 at 16:27
  • @EdSF - no, you can't have 2 ng-app for the same angular application, if you have 2 different index pages then you can do it, otherwise, include one module as a dependency of the other. – Tomer Jan 14 '16 at 07:39
  • @fatman - I already tried injecting one module into another, but that did not work and browser inspector did not show anything related to the injected module. – Tejaswini Devekar Jan 15 '16 at 12:30