簡體   English   中英

AngularJS模塊應用程序依賴性

[英]AngularJS module app dependency

我在app.js文件中聲明了twp應用程序模塊-“ requestDashboard”和“ newRequestDashboard” ...“ newRequestDashboard”取決於“ requestDashboard”(我有一個要顯示的對象數組。應用程序分配了不同的控制器,並且數組存儲在“ requestDashboard”中,我可能試圖對此進行復雜化,但是由於某種原因我無法顯示任何對象。

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"
                }
            ]
        }
    ];


});

在您的應用程序中通常有很多應用程序。 但是您應該采取其他方法。 在您的解決方案中,您聲明對所有應用程序的依賴。 如果您的應用程序變大,那將會發生沖突。 您應該是這樣的。

// 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']);

關於您的問題,為什么不使用服務? 並且可以在Controller中使用服務,然后可以顯示回到視圖。

希望這可以幫助

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM