I have all of my AngularJS controllers in one file, controllers.js.
(我将所有AngularJS控制器都放在一个文件controllers.js中。)
This file is structured as follows:(该文件的结构如下:)
angular.module('myApp.controllers', [])
.controller('Ctrl1', ['$scope', '$http', function($scope, $http) {
}])
.controller('Ctrl2', ['$scope', '$http', function($scope, $http) }
}])
What I'd like to do is put Ctrl1 and Ctrl2 into separate files.
(我想做的是将Ctrl1和Ctrl2放入单独的文件中。)
I would then include both files in my index.html, but how should that be structured?(然后我会在index.html中包含这两个文件,但是应该如何构建呢?)
I tried doing some thing like this and it throws an error in the web browser console saying it can't find my controllers.(我尝试做这样的事情,它在Web浏览器控制台中抛出一个错误,说它无法找到我的控制器。)
Any hints?(任何提示?)
I searched StackOverflow and found this similar question - however, this syntax is using a different framework (CoffeeScript) on top of Angular, and so I haven't been able to follow.
(我搜索了StackOverflow并发现了类似的问题 - 但是,这种语法在Angular之上使用了不同的框架(CoffeeScript),因此我无法遵循。)
AngularJS: How do I create controllers in multiple files
(AngularJS:如何在多个文件中创建控制器)
ask by Beebunny translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…