Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to register two modules to ng-app?

Tags:

angularjs

In my application I have two modules, which are used for routing. Here is the code of it

//Module1:

 angular.module('phonecat', []).
  config(['$routeProvider', function($routeProvider) {
  $routeProvider.
      when('/phones', {templateUrl: 'partials/phone-list.html',   controller: PhoneListCtrl}).
      when('/phones/:phoneId', {templateUrl: 'partials/phone-detail.html', controller: PhoneDetailCtrl}).
      otherwise({redirectTo: '/phones'});
}]);

Module2:

angular.module("computer",[]).config(['$routeProvider', function($routeProvider) {
$routeProvider.when('/test',{templateUrl:'mypath/my-list.html',controller:ComputerListCtrl});
}]);

As per angularJS document, I have to register these modules into ng-app, like this

<html lang="en" ng-app="phonecat">

But in the above code, at a time I can register only one module, that is, phoneCat moudle or computer module. Because of this, I am able load only one module data into the application.

So please guide me, how can I register both the module into ng-app, during bootsrap or is there any other way I can do this.

like image 824
niran Avatar asked Apr 26 '13 03:04

niran


1 Answers

You can create a top level module that will have your two modules as injected dependencies:

var app = angular.module('app', ['phonecat', 'computer']);

and then in your html use:ng-app="app"

like image 134
Bogdan Rybak Avatar answered Oct 03 '22 01:10

Bogdan Rybak