I cannot figure out how to write an npm module for angular2.
Despite the fact that I found 2 tutorials ( One , Two ), there is no description of how to implement the angular2 module ( @NgModule ) as an npm package.
What I donโt understand when I need, for example, to introduce a module, for example, BrowserModule ? Do I even need to insert it using my module or is it enough to just enter directives?
My plugin so far:
- https://github.com/yves-s/ng2-flexbox-grid/tree/develop
- https://www.npmjs.com/package/ng2-flexbox-grid
He is currently copying and updating RC6 from @btmorton angular2-grid
But I canโt make it work.
UPDATE:
This is the current state of my ng2-flexbox-grid.ts module
export * from './src/directives'; export * from './src/components'; export * from './src/interfaces'; import {BrowserModule} from '@angular/platform-browser'; import {NgModule} from '@angular/core'; import {CommonModule} from '@angular/common'; import {NgGrid, NgGridItem} from './src/directives'; const mapValuesToArray = (obj) => Object.keys(obj).map(key => obj[key]); // const directives = mapValuesToArray(directiveItems); export default { directives: [NgGrid, NgGridItem] } @NgModule({ declarations: [], imports: [ BrowserModule, CommonModule ], exports: [NgGrid, NgGridItem] }) export class Ng2FlexboxGridModule {}
UPDATE - Solution
With @Clint, I could bring this baby home.
Probably the biggest problem was that I did not know how @NgModule works. And I'm sure this would help if I carefully read @NgModule docs
The important part is to declare and export module directives. To do this, you just need to import the FlexboxGridModule in order to use the exported directives.
Export
import {BrowserModule} from '@angular/platform-browser'; import {NgModule} from '@angular/core'; import {NgGrid, NgGridItem} from './src/directives'; @NgModule({ imports: [BrowserModule], declarations: [NgGrid, NgGridItem], exports: [NgGrid, NgGridItem] }) export class FlexboxGridModule {}
Import
import {NgModule} from '@angular/core'; import {BrowserModule} from '@angular/platform-browser'; import {AppComponent} from './app.component'; import {FlexboxGridModule} from "ng2-flexbox-grid"; @NgModule({ imports: [ BrowserModule, FlexboxGridModule ], declarations: [AppComponent], bootstrap: [AppComponent] }) export class AppModule {}