【发布时间】:2013-12-10 14:51:58
【问题描述】:
我正在创建一个基于 AngularJS、Breeze 和 RequireJS 的单页应用程序。在使用 requirejs 设置 AMD 以与 Angular 和 Breeze 一起使用时,我遇到了 Breeze 对“q”的依赖性的问题。如果 "q" 的配置规则是小写的,即使 "shim" 中没有明确的导出,Breeze 也会给出这个错误:
Uncaught Error: Unable to initialize Q. See https://github.com/kriskowal/q
"http://localhost:1498/Scripts/shared/breeze.js"breeze.js:1`
当 require config 将所有引用从“q”更改为“Q”时(即使没有导出),代码也可以工作。有谁知道为什么会这样?
这是工作需要配置:
require.config({
baseUrl: '../Scripts',
paths: {
angular: 'shared/angular',
bootstrap: 'shared/ui-bootstrap',
dropdowns: 'app/directives/dropdowns',
employeeApp: 'app/modules/employeeModule',
controllers: 'app/controllers',
dates: 'app/directives/dates',
jquery: 'shared/jquery',
Q: 'shared/q',
breeze: 'shared/breeze',
config: 'app/services/config',
model: 'app/services/model',
dataservice: 'app/services/dataservice',
expenseInfo: 'app/services/expenseInfo'
},
shim: {
'angular': { 'exports': 'angular' },
'bootstrap': { deps: ['angular'] },
//'q': { 'exports': 'q' },
'breeze': { deps: ['Q', 'jquery'], 'exports': 'breeze' }
},
priority: [ 'angular', 'bootstrap', 'dropdowns', 'jquery',
'Q', 'breeze', 'employeeSearch', 'dates' ]
});
【问题讨论】:
-
查看 Ward 的这篇文章 - stackoverflow.com/questions/17819991/… - 应该有助于让您知道它发生的原因以及如何创建一个小作品
-
@PWKad,我认为这个错误更多地是在 requireJS 或 BreezeJS 上,而不是 Angular。 Ward 的例子是转换承诺。我认为这与 $q 或 Angular 的承诺无关。区别在于需要 'q' 和 'Q' - 如果你使用 'q' 则不会加载
-
有趣的是,使用 Angular q 而不是 Breeze Q 时存在问题。无论出于何种原因,Breeze 都不依赖于 jQuery。
-
嗯,Breeze 的默认适配器确实使用了 jQuery 的 .ajax ...
标签: javascript angularjs requirejs breeze q