15

在我的应用程序中,我有两个用于路由的模块。这是它的代码

//模块1:

 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'});
}]);

模块2:

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

根据 angularJS 文档,我必须将这些模块注册到ng-app中,就像这样

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

但是在上面的代码中,一次只能注册一个模块,即phoneCat模块或计算机模块。因此,我只能将一个模块数据加载到应用程序中。

所以请指导我,如何在引导过程中将两个模块都注册到 ng-app 中,或者有其他方法可以做到这一点。

4

1 回答 1

23

您可以创建一个顶级模块,将您的两个模块作为注入依赖项:

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

然后在你的 html 中使用:ng-app="app"

于 2013-04-26T04:32:30.330 回答