来自另一个模块的 Angularjs 路由控制器
Angularjs routing controller from another module
我正在构建一个大应用程序,我的结构是这样的:
每个模块都有自己的文件夹结构,用于控制器、指令等...
每个文件夹都有一个索引.js文件,然后是其他文件,用于分隔每个控制器、每个指令等......
索引.js文件包含模块的定义。例如,对于上述业务模块的控制器:
angular.module('myCompany.businessModule.controllers', []);
这里没有依赖项,但可能存在任何依赖项。
然后在 firstCtrl.js 中,我可以重用该模块并将控制器添加到其中:
angular.module('myCompany.businessModule.controllers').controller('firstCtrl', function(){
});
然后,应用程序.js通过将应用程序所需的所有模块添加到依赖项数组来聚合它们。
angular.module('myApp', ['myCompany.businessModule', 'myCompany.anotherBusinessModule'],'ngRoute');
现在是包含其他模块视图的路由。我的路线是这样的:
var myApp = angular.module('myApp');
myApp.config(function($routeProvider) {
$routeProvider
// route for the home page
.when('/', {
templateUrl : 'pages/home.html',
controller : 'mainController'
})
// route for the about page
.when('/about', {
templateUrl : 'pages/about.html',
controller : 'firstCtrl'
})
});
现在的问题是,我可以将一个控制器从另一个模块连接到注入了此模块的特定控制器,就像在myApp包含myCompany.businessModule.controller并具有firstCtrl时一样?
您的模块文件:
angular.module('myApp').config(function($routeProvider){
$routeProvider
// route for the home page
.when('/', {
templateUrl : 'pages/home.html',
controller : 'mainController'
})
// route for the about page
.when('/about', {
templateUrl : 'pages/about.html',
controller : 'firstCtrl'
});
});
当您想要使用它时,请将其作为依赖项包含在内。
angular.module('app',[other deps]);
相关文章:
- AngularJS路由没有'不起作用
- AngularJS路由在初次点击时没有加载ng模板
- AngularJS路由服务器端支持(NodeJS+express)
- 延迟 AngularJS 路由更改,直到加载模型以防止闪烁
- AngularJS 路由功能不起作用
- AngularJs 路由名称未更新
- 防止谷歌索引AngularJS路由
- Angularjs:路由后如何调用控制器函数
- 在 AngularJS 路由中使用常量
- AngularJS路由未绑定控制器
- 使用ng-include调用控制器时AngularJS路由解析
- 如何防止引导选项卡干扰angularjs路由
- 如何使AngularJS路由与index.html/#/myPage一样使用index.html#/myPpage
- AngularJS路由示例不起作用
- 从javascript触发AngularJS路由
- AngularJS 路由菜鸟
- 没有哈希“#”的 AngularJS 路由 - 无法让它工作
- IIS中的AngularJS路由
- AngularJS路由:URL中不必要的参数
- 如何让 angularJS 路由提供程序在路由更改之前执行操作