Angularjs 在meanjs中插入自定义模块的最佳实践

Angularjs 在meanjs中插入自定义模块的最佳实践,angularjs,meanjs,Angularjs,Meanjs,据我所知,没有经典的模块注册,我们可以在其中注入依赖项,如: var myModule = angular.module('myModule', [otherModule]); 但是,在目录的根目录下有文件module name.client.module.js 'use strict'; // Use Applicaion configuration module to register a new module ApplicationConfiguration.registerModule

据我所知,没有经典的模块注册,我们可以在其中注入依赖项,如:

var myModule = angular.module('myModule', [otherModule]);
但是,在目录的根目录下有文件
module name.client.module.js

'use strict';
// Use Applicaion configuration module to register a new module
ApplicationConfiguration.registerModule('module-name');
我可以像
*.registerModule('module-name',[someModule])那样在这里插入我的模块吗angular.module('articles').config(…)


但在
config
中,我只能注入
提供程序
,而不注入
工厂

,因为我使用了angular,这是加载自定义模块和外部库的最佳实践 就是把angularjs和requirejs结合起来

分三步完成

首先,在你的主HTML文件中加载一个JS文件,它建立了你的系统的基础(需要.CONFIG): 这里有所有允许的参数:

例如: 在html文件中:

<script src="path/to/require.js" data-main="path/to/yourBuildFile"></script>
其次,在同一个文件或另一个文件中(请参阅上面链接中的参数deps),引导应用程序: 就像这里解释的:

例如:

// AMD module injection, more info here : http://requirejs.org/docs/whyamd.html
define([ // inject all the external library you need + the definition of your app
    'angular',
    'require',
    'yourpath/yourApp' // don't bother here, it's explained in third point
], function(angular){
    // link your app to the document file programatically
    angular.bootstrap(document, ['nameOfYourApp']); 
});
define([
    'angular',
    // put all path to your directives + controllers + services
], function(angular){ // only specify parameters the library you use in the function
    // you create your sublime app :)
    angular.module('nameOfYourApp', [
        // put all the name of your modules injected above
    ]);
});
第三,定义应用程序(在“yourpath/yourApp”中)

例如:

// AMD module injection, more info here : http://requirejs.org/docs/whyamd.html
define([ // inject all the external library you need + the definition of your app
    'angular',
    'require',
    'yourpath/yourApp' // don't bother here, it's explained in third point
], function(angular){
    // link your app to the document file programatically
    angular.bootstrap(document, ['nameOfYourApp']); 
});
define([
    'angular',
    // put all path to your directives + controllers + services
], function(angular){ // only specify parameters the library you use in the function
    // you create your sublime app :)
    angular.module('nameOfYourApp', [
        // put all the name of your modules injected above
    ]);
});
上面的例子是针对单页应用程序的。 您可以在这里找到多页应用程序的其他示例