I'm trying to create a reusable library of components, mostly as an exercise to become familiar with the angular world. I've written a small standalone angular app for a legacy application, so I'm decidedly new to Angular, but I thought I understood the configuration well enough to do this. Apparently I'm missing something still.
I have two pieces:
- an Angular Library generated with
yo angular2-library. - an Angular CLI application generated with
ng new <library-name>.
These are both CLEAN (no changes after running the respective generators).
In the LIBRARY, I ran:
npm run buildto create the/distdirectory with the sample module/component/etccd dist && npm linkto link npm to the library as described here in the generator documentation
In the Angular CLI application, I ran:
npm link --save <library-name>- added
import {SampleModule} from 'library-name'toapp.module.ts - added
SampleModule.forRoot()to the imports array inapp.module.tsso it looks like[BrowserModule, SampleModule.forRoot()] - Added the
<sample-component></sample-component>to theapp.component.htmltemplate ng serve -oto compile and run.
I get an error in Chrome Dev Tools console:
Uncaught Error: Unexpected value '[object Object]' imported by the module 'AppModule'. Please add a @NgModule annotation.
Changing the imports array to [BrowserModule, SampleModule], I get:
Uncaught Error: Unexpected value 'SampleModule' imported by the module 'AppModule'. Please add a @NgModule annotation.
Not sure where to go from here.