Micro apps with Angular 7 - Zone.js and custom elements issues












0















I'm pretty new in developing Angular (7), because I think about the architecture for a new large web project. So I play a little bit with the possible options, especially using a micro frontend.



I created two angular projects -> "micro-app-shell" and "micro-app-a".



The shell is the outer container of the web application, which manages several micro-apps.



I read some articals about micro apps with angular and want to try the custom-elements approach.



"micro-app-a"



excerpt of "app.module.ts"



@NgModule({
declarations: [
AppComponent,
ClientAComponent
],
imports: [
BrowserModule
],
providers: ,
schemas: [CUSTOM_ELEMENTS_SCHEMA],
// bootstrap: [AppComponent]
entryComponents: [
ClientAComponent,
]
})
export class AppModule {

constructor(private injector: Injector) {

}

ngDoBootstrap() {
const appElement = createCustomElement(ClientAComponent, { injector: this.injector });
customElements.define('client-a', appElement);
}

}


"app.component.html"



<div style="text-align:center">
<h1>
Client A Micro App
</h1>
</div>


I build the application with following command:



ng build --output-hashing none --output-path C:/Dev/mdo_workspace/micro-app-test/micro-app-shell/src/assets/scripts


"micro-app-shell"



I added following to of index.html



 <script type="text/javascript" src="./assets/scripts/runtime.js"></script>
<script type="text/javascript" src="./assets/scripts/polyfills.js"></script>
<script type="text/javascript" src="./assets/scripts/styles.js"></script>
<script type="text/javascript" src="./assets/scripts/vendor.js"></script>
<script type="text/javascript" src="./assets/scripts/main.js"></script>


I extend the app.module.ts with schemas part



schemas: [CUSTOM_ELEMENTS_SCHEMA],


Now my questions/issues



1 a) When I uncomment in "micro-app-a" -> polyfills.js the zone.js import (import 'zone.js/dist/zone'; ) and run the "micro-app-shell" I get the error




Zone already loaded.




1 b) When I comment in "micro-app-a" -> polyfills.js the zone.js import (import 'zone.js/dist/zone'; ) and run the "micro-app-shell" I get the error




In this configuration Angular requires Zone.js




Wat is the right way to prevent this errors? Or can I irgnore it?



2) When I apply changes of question 1a and start the "micro-app-shell" I want to show the "micro-app-a" as custom element in app.comment.html like this:



<div>
<client-a></client-a>
</div>


The content of "micro-app-shell" - "app.component.html" is shown but I get the error:




Failed to construct 'HTMLElement': Please use the 'new' operator,
this DOM object constructor cannot be called as a function.




I following samples like this:



https://www.softwarearchitekt.at/post/2018/05/04/microservice-clients-with-web-components-using-angular-elements-dreams-of-the-near-future.aspx
https://www.ngdevelop.tech/angular-elements/



Thanks a lot for your help in advance!










share|improve this question



























    0















    I'm pretty new in developing Angular (7), because I think about the architecture for a new large web project. So I play a little bit with the possible options, especially using a micro frontend.



    I created two angular projects -> "micro-app-shell" and "micro-app-a".



    The shell is the outer container of the web application, which manages several micro-apps.



    I read some articals about micro apps with angular and want to try the custom-elements approach.



    "micro-app-a"



    excerpt of "app.module.ts"



    @NgModule({
    declarations: [
    AppComponent,
    ClientAComponent
    ],
    imports: [
    BrowserModule
    ],
    providers: ,
    schemas: [CUSTOM_ELEMENTS_SCHEMA],
    // bootstrap: [AppComponent]
    entryComponents: [
    ClientAComponent,
    ]
    })
    export class AppModule {

    constructor(private injector: Injector) {

    }

    ngDoBootstrap() {
    const appElement = createCustomElement(ClientAComponent, { injector: this.injector });
    customElements.define('client-a', appElement);
    }

    }


    "app.component.html"



    <div style="text-align:center">
    <h1>
    Client A Micro App
    </h1>
    </div>


    I build the application with following command:



    ng build --output-hashing none --output-path C:/Dev/mdo_workspace/micro-app-test/micro-app-shell/src/assets/scripts


    "micro-app-shell"



    I added following to of index.html



     <script type="text/javascript" src="./assets/scripts/runtime.js"></script>
    <script type="text/javascript" src="./assets/scripts/polyfills.js"></script>
    <script type="text/javascript" src="./assets/scripts/styles.js"></script>
    <script type="text/javascript" src="./assets/scripts/vendor.js"></script>
    <script type="text/javascript" src="./assets/scripts/main.js"></script>


    I extend the app.module.ts with schemas part



    schemas: [CUSTOM_ELEMENTS_SCHEMA],


    Now my questions/issues



    1 a) When I uncomment in "micro-app-a" -> polyfills.js the zone.js import (import 'zone.js/dist/zone'; ) and run the "micro-app-shell" I get the error




    Zone already loaded.




    1 b) When I comment in "micro-app-a" -> polyfills.js the zone.js import (import 'zone.js/dist/zone'; ) and run the "micro-app-shell" I get the error




    In this configuration Angular requires Zone.js




    Wat is the right way to prevent this errors? Or can I irgnore it?



    2) When I apply changes of question 1a and start the "micro-app-shell" I want to show the "micro-app-a" as custom element in app.comment.html like this:



    <div>
    <client-a></client-a>
    </div>


    The content of "micro-app-shell" - "app.component.html" is shown but I get the error:




    Failed to construct 'HTMLElement': Please use the 'new' operator,
    this DOM object constructor cannot be called as a function.




    I following samples like this:



    https://www.softwarearchitekt.at/post/2018/05/04/microservice-clients-with-web-components-using-angular-elements-dreams-of-the-near-future.aspx
    https://www.ngdevelop.tech/angular-elements/



    Thanks a lot for your help in advance!










    share|improve this question

























      0












      0








      0


      1






      I'm pretty new in developing Angular (7), because I think about the architecture for a new large web project. So I play a little bit with the possible options, especially using a micro frontend.



      I created two angular projects -> "micro-app-shell" and "micro-app-a".



      The shell is the outer container of the web application, which manages several micro-apps.



      I read some articals about micro apps with angular and want to try the custom-elements approach.



      "micro-app-a"



      excerpt of "app.module.ts"



      @NgModule({
      declarations: [
      AppComponent,
      ClientAComponent
      ],
      imports: [
      BrowserModule
      ],
      providers: ,
      schemas: [CUSTOM_ELEMENTS_SCHEMA],
      // bootstrap: [AppComponent]
      entryComponents: [
      ClientAComponent,
      ]
      })
      export class AppModule {

      constructor(private injector: Injector) {

      }

      ngDoBootstrap() {
      const appElement = createCustomElement(ClientAComponent, { injector: this.injector });
      customElements.define('client-a', appElement);
      }

      }


      "app.component.html"



      <div style="text-align:center">
      <h1>
      Client A Micro App
      </h1>
      </div>


      I build the application with following command:



      ng build --output-hashing none --output-path C:/Dev/mdo_workspace/micro-app-test/micro-app-shell/src/assets/scripts


      "micro-app-shell"



      I added following to of index.html



       <script type="text/javascript" src="./assets/scripts/runtime.js"></script>
      <script type="text/javascript" src="./assets/scripts/polyfills.js"></script>
      <script type="text/javascript" src="./assets/scripts/styles.js"></script>
      <script type="text/javascript" src="./assets/scripts/vendor.js"></script>
      <script type="text/javascript" src="./assets/scripts/main.js"></script>


      I extend the app.module.ts with schemas part



      schemas: [CUSTOM_ELEMENTS_SCHEMA],


      Now my questions/issues



      1 a) When I uncomment in "micro-app-a" -> polyfills.js the zone.js import (import 'zone.js/dist/zone'; ) and run the "micro-app-shell" I get the error




      Zone already loaded.




      1 b) When I comment in "micro-app-a" -> polyfills.js the zone.js import (import 'zone.js/dist/zone'; ) and run the "micro-app-shell" I get the error




      In this configuration Angular requires Zone.js




      Wat is the right way to prevent this errors? Or can I irgnore it?



      2) When I apply changes of question 1a and start the "micro-app-shell" I want to show the "micro-app-a" as custom element in app.comment.html like this:



      <div>
      <client-a></client-a>
      </div>


      The content of "micro-app-shell" - "app.component.html" is shown but I get the error:




      Failed to construct 'HTMLElement': Please use the 'new' operator,
      this DOM object constructor cannot be called as a function.




      I following samples like this:



      https://www.softwarearchitekt.at/post/2018/05/04/microservice-clients-with-web-components-using-angular-elements-dreams-of-the-near-future.aspx
      https://www.ngdevelop.tech/angular-elements/



      Thanks a lot for your help in advance!










      share|improve this question














      I'm pretty new in developing Angular (7), because I think about the architecture for a new large web project. So I play a little bit with the possible options, especially using a micro frontend.



      I created two angular projects -> "micro-app-shell" and "micro-app-a".



      The shell is the outer container of the web application, which manages several micro-apps.



      I read some articals about micro apps with angular and want to try the custom-elements approach.



      "micro-app-a"



      excerpt of "app.module.ts"



      @NgModule({
      declarations: [
      AppComponent,
      ClientAComponent
      ],
      imports: [
      BrowserModule
      ],
      providers: ,
      schemas: [CUSTOM_ELEMENTS_SCHEMA],
      // bootstrap: [AppComponent]
      entryComponents: [
      ClientAComponent,
      ]
      })
      export class AppModule {

      constructor(private injector: Injector) {

      }

      ngDoBootstrap() {
      const appElement = createCustomElement(ClientAComponent, { injector: this.injector });
      customElements.define('client-a', appElement);
      }

      }


      "app.component.html"



      <div style="text-align:center">
      <h1>
      Client A Micro App
      </h1>
      </div>


      I build the application with following command:



      ng build --output-hashing none --output-path C:/Dev/mdo_workspace/micro-app-test/micro-app-shell/src/assets/scripts


      "micro-app-shell"



      I added following to of index.html



       <script type="text/javascript" src="./assets/scripts/runtime.js"></script>
      <script type="text/javascript" src="./assets/scripts/polyfills.js"></script>
      <script type="text/javascript" src="./assets/scripts/styles.js"></script>
      <script type="text/javascript" src="./assets/scripts/vendor.js"></script>
      <script type="text/javascript" src="./assets/scripts/main.js"></script>


      I extend the app.module.ts with schemas part



      schemas: [CUSTOM_ELEMENTS_SCHEMA],


      Now my questions/issues



      1 a) When I uncomment in "micro-app-a" -> polyfills.js the zone.js import (import 'zone.js/dist/zone'; ) and run the "micro-app-shell" I get the error




      Zone already loaded.




      1 b) When I comment in "micro-app-a" -> polyfills.js the zone.js import (import 'zone.js/dist/zone'; ) and run the "micro-app-shell" I get the error




      In this configuration Angular requires Zone.js




      Wat is the right way to prevent this errors? Or can I irgnore it?



      2) When I apply changes of question 1a and start the "micro-app-shell" I want to show the "micro-app-a" as custom element in app.comment.html like this:



      <div>
      <client-a></client-a>
      </div>


      The content of "micro-app-shell" - "app.component.html" is shown but I get the error:




      Failed to construct 'HTMLElement': Please use the 'new' operator,
      this DOM object constructor cannot be called as a function.




      I following samples like this:



      https://www.softwarearchitekt.at/post/2018/05/04/microservice-clients-with-web-components-using-angular-elements-dreams-of-the-near-future.aspx
      https://www.ngdevelop.tech/angular-elements/



      Thanks a lot for your help in advance!







      angular microservices zone.js






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Dec 28 '18 at 14:46









      IsgamIsgam

      32




      32
























          1 Answer
          1






          active

          oldest

          votes


















          0














          You check my sample project here
          https://github.com/xmlking/angular-elements-in-angular-shell
          I am still planing improve developer experience






          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53960284%2fmicro-apps-with-angular-7-zone-js-and-custom-elements-issues%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            You check my sample project here
            https://github.com/xmlking/angular-elements-in-angular-shell
            I am still planing improve developer experience






            share|improve this answer




























              0














              You check my sample project here
              https://github.com/xmlking/angular-elements-in-angular-shell
              I am still planing improve developer experience






              share|improve this answer


























                0












                0








                0







                You check my sample project here
                https://github.com/xmlking/angular-elements-in-angular-shell
                I am still planing improve developer experience






                share|improve this answer













                You check my sample project here
                https://github.com/xmlking/angular-elements-in-angular-shell
                I am still planing improve developer experience







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Jan 6 at 17:37









                xmlkingxmlking

                291314




                291314






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53960284%2fmicro-apps-with-angular-7-zone-js-and-custom-elements-issues%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Monofisismo

                    Angular Downloading a file using contenturl with Basic Authentication

                    Olmecas