2017-11-21 14 views
0

複数のコンポーネントで配布する角度ライブラリを作成しようとしていますが、動作させることができませんでした。 1つのコンポーネントでのみ動作します。これは私が1つのコンポーネントのために作った方法です:複数のコンポーネントで配布する角型ライブラリを作成する方法

私はsample-libraryというフォルダを持っています。 SRC内部で私が持っている:

package.json

{ 
    "name": "sample-library", 
    "version": "0.1.0", 
    "author": { 
    "name": "IG" 
    }, 
    "keywords": [ 
    "angular" 
    ], 
    "license": "MIT", 
    "main": "sample-library.umd.js", 
    "module": "sample-library.js", 
    "jsnext:main": "sample-library.js", 
    "typings": "sample-library.d.ts", 
    "peerDependencies": { 
    ... 
    } 
} 

tsconfig.es5.json

{ 
    "compilerOptions": { 
    "declaration": true, 
    "module": "es2015", 
    "target": "es5", 
    "baseUrl": ".", 
    "stripInternal": true, 
    "emitDecoratorMetadata": true, 
    "experimentalDecorators": true, 
    "moduleResolution": "node", 
    "outDir": "../build", 
    "rootDir": ".", 
    "lib": [ 
     "es2015", 
     "dom" 
    ], 
    "skipLibCheck": true, 
    "types": [] 
    }, 
    "angularCompilerOptions": { 
    "annotateForClosureCompiler": true, 
    "strictMetadataEmit": true, 
    "skipTemplateCodegen": true, 
    "flatModuleOutFile": "sample-library.js", 
    "flatModuleId": "sample-library" 
    }, 
    "files": [ 
    "./index.ts" 
    ] 
} 

index.ts

import { NgModule, ModuleWithProviders } from '@angular/core'; 
import { CommonModule } from '@angular/common'; 
import { SampleComponent } from './sample.component'; 

export * from './sample.component'; 

@NgModule({ 
    imports: [ 
    CommonModule 
    ], 
    declarations: [ 
    SampleComponent 
    ], 
    exports: [ 
    SampleComponent 
    ] 
}) 
export class SampleModule { 
    static forRoot(): ModuleWithProviders { 
    return { 
     ngModule: SampleModule, 
     providers: [] 
    }; 
    } 
} 

私はまた、サンプルlibrary.component.hmlサンプルlibrary.component.scssサンプルlibrary.component.ts SRC内部を持っています。

この方法で正しく動作します。しかし、同様の方法で同じライブラリに別のコンポーネントを追加する方法がわかりません。何か案が?

答えて

0

私が知っている限り、htereはこれを行う「標準的な」方法ではありません。私はドキュメントで何も見たことがありませんでした。 はとにかく、チュートリアルで、このことについていくつかのブログの記事があります。

0

あなたのngModuleのexportsパラメータにしたいとあなたは同じように、できるだけ多くのコンポーネントを追加することができます。

@NgModule({ 
    imports: [ 
    CommonModule 
    ], 
    declarations: [ 
    SampleComponent, 
    SampleComponent2, 
    ], 
    exports: [ 
    SampleComponent, 
    SampleComponent2, 
    ] 
}) 

ここでの動作例: https://github.com/plone/plone.restapi-angular/blob/master/src/module.ts#L118

私はindex.tsであなたのngModuleを実装しないことをお勧めしますが、module.tsのような区切りファイルで、そしてindex.tsで、ちょうどすべてのアイテム(ngModule、コンポーネント、サービス、など)をエクスポートします。

関連する問題