Gabu
Gabu

Reputation: 388

Is it possible for angular2 to import components from another angular2 project?

Having the structure below:

/project1
   /app
      /components
      /services
index.html

/project2
   /app
      /components
      /services
index.html

Is it possible to import a component or service from project2 to project1 and vice versa?

Upvotes: 3

Views: 123

Answers (2)

sethu palaniyappan
sethu palaniyappan

Reputation: 719

To import the component (or) service from another angular2 project you follow the following steps

  1. export the needed component and service from a project 1.
  2. install that project using npm (example : npm install ../project1)
  3. Add the path in System config file
  4. Now the exported component and services are accesable in project 2,So you can import the project1 components and services as per your need.

Upvotes: 0

Thierry Templier
Thierry Templier

Reputation: 202138

You could configure SystemJS to use both folders in your index.html file. This way you will be able to import project elements into another one.

<script>
  System.config({
    packages: {        
      'project1/app': {
        format: 'register',
        defaultExtension: 'js'
      },
      'project2/app': {
        format: 'register',
        defaultExtension: 'js'
      }
    }
  });
  System.import('project1/app/boot')
        .then(null, console.error.bind(console));
</script>

Upvotes: 4

Related Questions