2014-10-21 173 views
0

我已經在我的app.js文件 - 「requestDashboard」和「newRequestDashboard」中聲明瞭twp應用模塊...「newRequestDashboard」依賴於「requestDashboard」(我有一個對象數組,這兩個應用程序有不同的控制器分配給他們和陣列存儲在「requestDashboard」我可能試圖過度複雜這一點,但我不能因爲某種原因顯示任何對象。代碼如下:AngularJS模塊應用依賴

app.js:

angular.module('requestDashboard', ['ngRoute', 'ui.bootstrap']); 

angular.module('newRequestDashboard', ['ngRoute', 'ui.bootstrap', 'requestDashboard']); 

控制器在 「requestDashboard」

angular.module("requestDashboard") 
.controller('requestDashboardCtrl', function ($scope) { 

    //Dummy Data for user requests 
    $scope.requests = [ 
     { 
      type: "meeting1", 
      meetingName: "Radiology San Diego", 
      location:"Sheraton Ballroom 5S", 
      subitems: [ 
       { 
        name: "ESCALATED", 
        desc: "Power strips at every table", 
        priority:"1", 
        planner:"Jessica Q. Planner", 
        time:"02/15/15 at 8:15 AM", 
        quantity:"3; one power strip at ever table" 

       }, 
       { 
        name: "OPEN", 
        desc: "Extra table for 3", 
        priority:"3", 
        planner:"Jessica Q. Planner" 
       }, 
       { 
        name: "ACKNOWLEDGED", 
        desc: "Projector for meeting", 
        priority:"2", 
        planner:"Jessica Q. Planner" 
       }, 
       { 
        name: "CLOSED", 
        desc: "book exta room for 2 guests", 
        priority:"5", 
        planner:"Jessica Q. Planner" 
       }, 
       { 
        name: "CANCELLED", 
        desc: "extra chairs", 
        priority:"1", 
        planner:"Jessica Q. Planner" 
       } 
      ] 
     }, 
     { 
      type: "meeting2", 
      meetingName: "California Almond Growers", 
      location:"Sheraton FL14", 
      subitems: [ 
       { 
        name: "ESCALATED", 
        desc: "need some more almonds", 
        priority:"1", 
        planner:"Jessica Q. Planner" 
       }, 
       { 
        name: "OPEN", 
        desc: "extra pamphlets", 
        priority:"4", 
        planner:"Jessica Q. Planner" 
       }, 
       { 
        name: "ACKNOWLEDGED", 
        desc: "Power supply", 
        priority:"2", 
        planner:"Jessica Q. Planner" 
       } 
      ] 
     }, 
     { 
      type: "meeting3", 
      meetingName: "Association of Amateur Archaeologists", 
      location:"Ansley 1- FL14", 
      subitems: [ 
       { 
        name: "ESCALATED", 
        desc: "need some more experience", 
        priority:"1", 
        planner:"Jessica Q. Planner" 
       }, 
       { 
        name: "OPEN", 
        desc: "need dinosaurs", 
        priority:"3", 
        planner:"Jessica Q. Planner" 
       } 
      ] 
     } 
    ]; 


}); 

回答

0

在您的應用程序中有很多應用程序是很常見的。但是你應該採取不同的方法。在你的解決方案中,你聲明依賴於你的所有應用程序。如果您的應用程序變得更大,這會衝突。你應該如此是這樣的。

// declare your app without any dependency 
(function() { 
    var requestDashboard= angular.module('requestDashboard',[]); 
}()); 

(function() { 
    var newRequestDashboard= angular.module('newRequestDashboard',[]); 
}()); 


// inject all your dependency here 
var mainApp = angular.module('mainApp ', ['requestDashboard','newRequestDashboard','ngRoute', 'ui.bootstrap']); 

關於你的問題,你爲什麼不使用服務?並且可以在控制器中使用服務,然後您可以顯示回您的視圖。

希望這有助於

+0

上的服務+1好點...但對於服務,該陣列將在兩個不同的控制器,在兩個不同的模塊一起使用。如果是這種情況,我將如何設置該服務?另外,您的答案中的「requestDashboard」被注入了兩次? – 2014-10-22 12:41:34