我不得不面對一個巨大的angularjs應用程序,UI部分將由dojo實現。如何在角度應用程序中使用requirejs來要求dojox?
我的項目是一個angularjs應用程序,它的結構是這樣的:
- 公共
- 腳本
- 庫
- 角
- 道場
- 道場
- 的dijit
- DojoX中
- require.js
- 模塊
- 子directive1.js
- 子directive2.js
- 子app.js
- main.js
- 庫
- 的index.html
- 腳本
在文件主index.html文件
<script data-main="scripts/main" src="scripts/libs/require.js"></script>
.js
require.config({
baseUrl: "scripts",
paths: {
......
, dojo: "libs/dojo/dojo"
, dijit: "libs/dojo/dijit"
, dojox: "libs/dojo/dojox"
}
});
文件中
子app.js
define([...], function (...) {
var app = angular.module("subApp",["ngRoute"]);
app.config([
//config something
]);
app.run([
// do something in runing phase
]);
return app;
});
在文件子directive1.js
,我需要的dijit /日曆以創建子指令1日曆控件。它運行良好,requirejs可以輕鬆找到「dijit/Calendar」。
define([
"./sub-app"
], function(app) {
app.directive("subDirective1",
function() {
return {
restrict: "E",
replace: true,
link: function (scope, iElement, iAttrs){
......
require([
"dijit/Calendar",
"dojo/date",
"dojo/domReady!"
], function(Calendar, date){
new Calendar({
value: new Date(),
isDisabledDate: function(d){
var d = new Date(d); d.setHours(0, 0, 0, 0);
var today = new Date(); today.setHours(0, 0, 0, 0);
return Math.abs(date.difference(d, today, "week")) > 0;
}
}, iElement);
});
}
}
}
);
});
在文件sub-directive2.js中,我需要dojox/charting/Chart來在子指令2中創建一個列圖。但它不能正常工作,我的瀏覽器輸出: 無法加載資源:服務器與404(未找到)狀態http://localhost:63342/public/scripts/libs/dojo/dojox.js
define([
"./sub-app"
], function(app) {
app.directive("subDirective2",
function() {
return {
restrict: "E",
replace: true,
link: function (scope, iElement, iAttrs){
......
require(["dojox/charting/Chart",
......
"dojo/ready"],
function(Chart, Default, Lines, Wetland, ready){
ready(function(){
var c = new Chart("chart3");
.....
iElement.append(chart1);
});
});
}
}
}
);
});
我婉知道爲什麼requirejs可以找到迪吉路徑迴應正確,但沒有找到正確的dojox路徑?它認爲dojox是一個JavaScript文件而不是目錄。 這是什麼使我感到困惑!