Accessing main.js file from 1 angular app exporting angular element into a container angular app

31 views Asked by At

`I have 2 angular applications running on localhost:4200 and localhost:4201.

In localhost:4200, I have converted the complete AppComponent into an angular element .

I have built the project, concatenated all the .js files into a main.js file.

If I try to access this main.js file in the index.html of the app running on localhost:4201 using

<script src="http://localhost:4200/main.js"></script>, 

then the main.js does get downloaded but the angular element does not show in the component.

If copy the main.js from localhost:4200 to the assets of localhost:4021 and reference the path of the file "src/assets/main.js" in scripts of angular.json, then it works perferctly.

But for runtime integration, I need to access the main.js via script tag. How do I make it work ?

Below didn't work in localhost:4201

  <script src="http://localhost:4200/main.js"></script>

Below worked in localhost:4201

 "scripts": ["src/assets/main.js"]

But for runtime integration, the <script> solution needs to work.

0

There are 0 answers