Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

angular

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?

like image 640
Gabu Avatar asked May 24 '26 19:05

Gabu


1 Answers

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>
like image 53
Thierry Templier Avatar answered May 26 '26 14:05

Thierry Templier



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!