2014-01-23 15 views
0

我不得不面對一個巨大的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文件而不是目錄。 這是什麼使我感到困惑!

回答

1

好的。 沒有人回覆。 我自己克服了它。 我們應該做2步,當我們要使用requirejs要求道場/的dijit/DojoX中

  1. 沒有使用realease代碼,而不是發展的源代碼
  2. 使用的軟件包配置道場不能使用的路徑

    包: { 名稱: '道場', 位置: '庫/道場/道場' },{ 名稱: '的dijit', 位置: '庫/道場/的dijit' },{ 名: 'DojoX中', 位置: '庫/道場/ DojoX中' } ],

相關問題