如何将两个模块注册到ng-app? [英] How to register two modules to ng-app?
问题描述
在我的应用程序中,我有两个用于路由的模块.这是它的代码
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'});
}]);
模块2:
angular.module("computer",[]).config(['$routeProvider', function($routeProvider) {
$routeProvider.when('/test',{templateUrl:'mypath/my-list.html',controller:ComputerListCtrl});
}]);
根据angularJS文档,我必须将这些模块注册到 ng-app 中,
As per angularJS document, I have to register these modules into ng-app, like this
<html lang="en" ng-app="phonecat">
但是在上面的代码中,一次只能注册一个模块,即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.
因此,请引导我,如何在Bootsrap期间将两个模块都注册到ng-app中,或者还有其他方法可以做到这一点.
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.
推荐答案
您可以创建一个顶层模块,该模块将把您的两个模块作为注入的依赖项:
You can create a top level module that will have your two modules as injected dependencies:
var app = angular.module('app', ['phonecat', 'computer']);
,然后在您的html中使用:ng-app="app"
and then in your html use:ng-app="app"
这篇关于如何将两个模块注册到ng-app?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!