我建议您使用新样式的注册控制器(至少从 开始1.0.3
,可能也是1.0.1
如此)
(function() {
//this will simulate creating the app with all needed dependencies
var app = angular.module('app', ['my.dependecy1', 'my.dependecy1']);
//...init code maybe
});
(function() {
//this will only retrieve it or create if it it doesn't exist
//I suggest you create it in another place passing all needed dependencies
var app = angular.module('app');
//I also recommend listing injectable variables manually,
//this way if you ever need minification you're safe
app.controller('IndexController', ['$scope', 'shoppingItems',
function IndexController($scope, shoppingItems) {
$scope.items = shoppingItems;
}
]);
}());