2017-09-28 158 views
3

我對Angular非常陌生,正在尋找一些有關基本概念的幫助。目前,我有一個模塊具有我想在單獨模塊中訪問的功能和屬性。如何將Angular模塊包含在單獨的模塊中

這是我想訪問代碼:

(function() { 
    'use strict'; 

var recentItemRepoDep = [ 
'repository', 
recentItemRepository 
]; 

var repoName = 'spRecentItemRepository'; 

angular 
    .module('repository') 
    .run(repoSelfRegister(repoName)) 
    .factory(repoName, recentItemRepoDep); 

function recentItemRepository(repository) { 
    var repo = repository('APIRecentItem', { 
    primaryKeys: [/*'UserName',*/ 'ItemID'] 
    }); 

    return repo; 
} 
})(); 

這裏就是我想實現上面的代碼中的代碼的開頭:

(function() { 
'use strict'; 

var salesDocumentMenuCtrlDep = [ 
    '$scope', 
    '$state', 
    '$stateParams', 
    'repos', 
    'spTabBarViewModel', 
    'spLoader', 
    'spCurrentUser', 
    'salesDocsVal', 
    salesDocumentMenuCtrl 
]; 

angular 
    .module('salesDocumentModule') 
    .controller('salesDocumentMenuCtrl', salesDocumentMenuCtrlDep); 

我想知道如果有一種方法可以將一個模塊注入另一個模塊,但我嘗試過的所有東西迄今爲止都沒有工作。

+0

爲了獲得更好的反饋,你應該知道,你在呼喚「角」,現在應該被稱爲' AngularJS」。 'Angular'被認爲是指'Angular 2/4'。 – rjustin

回答

1

您可以在一個主模塊注入其他模塊是這樣的:

angular 
    .module('mainModule', ['other', 'modules', 'goes', 'here']); 

而這種注射模塊可以有其他的注射子模塊,等等。

1

方式注入模塊或依賴:

var App = angular.module("App", ['ui.event', 'ngResource', 'ngAnimate', ...]); 

或另一種方式:

var app = angular.module('app'); 
app.requires.push('newDependency');