我使用require.js,angular.js和angular-route.js构建我的Angular应用程序。
我的main.js如下:
require.config({
// alias libraries paths
paths: {
'angular': 'libs/angular',
'domReady': 'libs/domReady',
'angularRoute': 'libs/angular-route'
},
// angular does not support AMD out of the box, put it in a shim
shim: {
'angular' : {'exports' : 'angular'},
},
// kick start application
deps: ['./bootstrap/bootstrap',
'./libs/angular-route',
'./libs/bootstrap'
]
});
我仍然遇到这个奇怪的错误:
[错误] TypeError:undefined不是对象(评估' angular.module') (anonieme functie)(angular-route.js,第24行) 全局代码(angular-route.js,第992行)
有人知道如何解决这个问题吗?
非常感谢!
答案 0 :(得分:0)
您还需要依赖添加角度js。
从
更新deps: ['./bootstrap/bootstrap',
'./libs/angular-route',
'./libs/bootstrap'
]
到
deps: ['./bootstrap/bootstrap',
'angular', // add require dependency of angular
'angularRoute', // use path as set in require config
'./libs/bootstrap'
]
答案 1 :(得分:0)
我终于解决了这个问题:
paths: {
'angular' : './libs/angular',
'domReady' : './libs/domReady',
'jQuery' : './libs/jquery',
'uiRouter' : './libs/angular-ui-router',
'bootstrap': './libs/bootstrap'
},
// angular does not support AMD out of the box, put it in a shim
shim: {
'angular': {
exports: 'angular',
deps: ['jQuery']
},
'uiRouter': {
deps: ['angular']
},
'bootstrap': {
deps: ['angular']
},
},
});
require(['./bootstrap']);
答案 2 :(得分:0)
我曾使用Yeoman脚手架来引导我的项目,并发现karma文件默认不包含浏览器测试中的单个文件。
更新Angular以包含修复此问题:
{pattern: 'bower_components/angular/angular.js', included: true },
{pattern: 'bower_components/angular-ui-router/release/angular-ui-router.js', included: false },