4

私が理解したように、モジュールの古典的な登録はなく、次のように依存関係を注入できます。

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私は注入することができprovidersますfactories

4

1 に答える 1

1

angular を使用する限り、カスタム モジュールと外部ライブラリをロードするベスト プラクティスは、angularjs と requirejs を組み合わせることです。

3ステップで出来上がります。

最初に、メインの html ファイルに、システムの基盤を構築する js ファイル (require.config) をロードします。ビルド/example.build.js

例: あなたの html ファイルで:

<script src="path/to/require.js" data-main="path/to/yourBuildFile"></script>

あなたのBuildFileファイルで:

require.config({
    // you can define suitable names for all your external js library
    paths:{
        // don't put a ".js" at the end of the file
        'angular' : 'path/angular',
        'underscore' : 'path/underscore-min',
        '...': '...',
    },
    // and other useful things
});

次に、同じファイルまたは別のファイル (上記のリンクのパラメーター deps を参照) で、アプリをブートストラップします。ここで説明したように: https://docs.angularjs.org/guide/bootstrap

例:

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

3 番目に、アプリを定義します ("yourpath/yourApp" 内)。

例:

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

上記の例は、単一ページのアプリケーション用に作成されています。ここでマルチページアプリケーションの他の例を見つけることができます http://requirejs.org/docs/start.html

于 2015-01-30T16:09:43.240 に答える