在我的应用程序中,我这样做:
angular.module('myApp.controllers', ['ngCookies']).
controller('AppCtrl', function ($scope, socket, $cookies) {
console.log("socket:");
console.log(socket);
$scope.component = 'main';
gLoggedIn = "no";
gUserName = "";
console.log("reset logged in status");
sid = $cookies;
$scope.setComponent = function(val) {
$scope.component = val;
}
}).
但我一直收到错误:
TypeError: 'undefined' is not an object (evaluating 'angular.module')" and "Error: No module: ngCookies
显然我在模块中加载['ngCookies']!而且,我做了一个角度,角度曲奇和角度加载器的凉亭安装,并将其添加到我的index.jade:
script(src='bower_components/angular-cookies/angular-cookies.js')
script(src='bower_components/angular/angular.js')
script(src='bower_components/angular-loader/angular-loader.js')
那是什么给出的?
我尝试在各个地方添加['ngCookies']无济于事:app.js,nope; services.js,nope;那有什么问题?
答案 0 :(得分:18)
在加载angular.js之前,您正在加载angular-cookies。像这样重新排列:
script(src='bower_components/angular/angular.js')
script(src='bower_components/angular-cookies/angular-cookies.js')
script(src='bower_components/angular-loader/angular-loader.js')
我认为这将解决您的问题。
答案 1 :(得分:14)
我有完全相同的失败,但使用yeoman angular generator创建了一个全新的proyect。我用grunt test命令得到了错误,我意识到问题是karma.conf.js没有加载angular-cookies(angular-resources和angular-sanitize)依赖项。所以我把它们添加到这个文件的文件数组中。
files: [
'app/bower_components/angular/angular.js',
'app/bower_components/angular-cookies/angular-cookies.js',
'app/bower_components/angular-resource/angular-resource.js',
'app/bower_components/angular-sanitize/angular-sanitize.js',
'app/bower_components/angular-mocks/angular-mocks.js',
'app/scripts/*.js',
'app/scripts/**/*.js',
'test/mock/**/*.js',
'test/spec/**/*.js'
],
它有效!
我希望它对yeoman用户有用!