Daniel Morozov Daniel Morozov - 5 months ago 19
TypeScript Question

Separate the logic in projects Angular 2

I have 3 projects Angular 2. They are written on typescript. All the projects have the same models and services. How can I make them at a global level and then connect to each of the projects?


One way to do this is:

  1. Define your models in the separate project (folder).
  2. Create package.json with main field pointing to your entry file (sample) inside the folder created.
  3. If you do not want to make your lib public do not forget to set "private": true
  4. In case of public package - publish it to npm and then consume it by running npm install for it from your other projects.
  5. If it is a private package - copy it to your projects root directory (or other place within) and consume by import * as myLib from "./path/to/myLib";

Hope this helps.