How can I load angular components in a page in sequence?












0















My problem scenario is as follows,



I have a page with a large form (+100 inputs). These inputs are divided into sections and those sections are developed as different components (for reusing purposes). So the general layout of the page is something like this,



<div>
<form-section-a></form-section-a>
<form-section-b></form-section-b>
<form-section-c></form-section-c>
...
<form-section-z></form-section-z>
</div>


Each form section will take some time to process because most of the inputs are material select boxes, and necessary data need to be loaded from the REST API and processed.



In the above shown layout, angular will try to render all form sections at once, hence adding up processing times of each section, which will cause the browser to freeze.



So, my plan is to load sections one after the other. Is there any recommended way to achieve this?



I have tried to write a structural directive to load components one after the other. Even though the directive works, there is no way I can know when the component has finished its internal processing work (May be the AfterViewInit hook). The directive looks something like this,



<div tcSequentialRenderer>
<form-section-a *tcIfPreviousBlockLoaded></form-section-a>
<form-section-b *tcIfPreviousBlockLoaded></form-section-b>
<form-section-c *tcIfPreviousBlockLoaded></form-section-c>
...
<form-section-z *tcIfPreviousBlockLoaded></form-section-z>
</div>


.



@Directive({selector: '[tcSequentialRenderer]'})
export class SequentialRendererDirective implements AfterViewInit {

@ContentChildren(IfPreviousBlockLoadedDirective) directives: QueryList<IfPreviousBlockLoadedDirective>;

ngAfterViewInit() {
// start from first item
if (this.directives.length > 0) {
this.directives.toArray()[0].show();
}

let directivesArray = this.directives.toArray();
for (let i = 1; i < directivesArray.length; i++) {
directivesArray[i - 1].done.subscribe(status => {
if (status) {
directivesArray[i].show();
}
});
}
}
}


.



@Directive({selector: '[tcIfPreviousBlockLoaded]'})
export class IfPreviousBlockLoadedDirective {

private isShown = false;

public done: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(false);

constructor(
private tplref: TemplateRef<any>,
private vcref: ViewContainerRef
) { }

public show(): void {
if (!this.isShown) {
this.vcref.createEmbeddedView(this.tplref);
this.isShown = true;
}
}
}


If I can somehow access the associated component from the IfPreviousBlockLoadedDirective this method will work seamlessly.



Are there any suggestions to fix this, or are there any other ways to achieve this without changing the form-section components?



NOTE: Form sections can be any angular component.










share|improve this question



























    0















    My problem scenario is as follows,



    I have a page with a large form (+100 inputs). These inputs are divided into sections and those sections are developed as different components (for reusing purposes). So the general layout of the page is something like this,



    <div>
    <form-section-a></form-section-a>
    <form-section-b></form-section-b>
    <form-section-c></form-section-c>
    ...
    <form-section-z></form-section-z>
    </div>


    Each form section will take some time to process because most of the inputs are material select boxes, and necessary data need to be loaded from the REST API and processed.



    In the above shown layout, angular will try to render all form sections at once, hence adding up processing times of each section, which will cause the browser to freeze.



    So, my plan is to load sections one after the other. Is there any recommended way to achieve this?



    I have tried to write a structural directive to load components one after the other. Even though the directive works, there is no way I can know when the component has finished its internal processing work (May be the AfterViewInit hook). The directive looks something like this,



    <div tcSequentialRenderer>
    <form-section-a *tcIfPreviousBlockLoaded></form-section-a>
    <form-section-b *tcIfPreviousBlockLoaded></form-section-b>
    <form-section-c *tcIfPreviousBlockLoaded></form-section-c>
    ...
    <form-section-z *tcIfPreviousBlockLoaded></form-section-z>
    </div>


    .



    @Directive({selector: '[tcSequentialRenderer]'})
    export class SequentialRendererDirective implements AfterViewInit {

    @ContentChildren(IfPreviousBlockLoadedDirective) directives: QueryList<IfPreviousBlockLoadedDirective>;

    ngAfterViewInit() {
    // start from first item
    if (this.directives.length > 0) {
    this.directives.toArray()[0].show();
    }

    let directivesArray = this.directives.toArray();
    for (let i = 1; i < directivesArray.length; i++) {
    directivesArray[i - 1].done.subscribe(status => {
    if (status) {
    directivesArray[i].show();
    }
    });
    }
    }
    }


    .



    @Directive({selector: '[tcIfPreviousBlockLoaded]'})
    export class IfPreviousBlockLoadedDirective {

    private isShown = false;

    public done: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(false);

    constructor(
    private tplref: TemplateRef<any>,
    private vcref: ViewContainerRef
    ) { }

    public show(): void {
    if (!this.isShown) {
    this.vcref.createEmbeddedView(this.tplref);
    this.isShown = true;
    }
    }
    }


    If I can somehow access the associated component from the IfPreviousBlockLoadedDirective this method will work seamlessly.



    Are there any suggestions to fix this, or are there any other ways to achieve this without changing the form-section components?



    NOTE: Form sections can be any angular component.










    share|improve this question

























      0












      0








      0








      My problem scenario is as follows,



      I have a page with a large form (+100 inputs). These inputs are divided into sections and those sections are developed as different components (for reusing purposes). So the general layout of the page is something like this,



      <div>
      <form-section-a></form-section-a>
      <form-section-b></form-section-b>
      <form-section-c></form-section-c>
      ...
      <form-section-z></form-section-z>
      </div>


      Each form section will take some time to process because most of the inputs are material select boxes, and necessary data need to be loaded from the REST API and processed.



      In the above shown layout, angular will try to render all form sections at once, hence adding up processing times of each section, which will cause the browser to freeze.



      So, my plan is to load sections one after the other. Is there any recommended way to achieve this?



      I have tried to write a structural directive to load components one after the other. Even though the directive works, there is no way I can know when the component has finished its internal processing work (May be the AfterViewInit hook). The directive looks something like this,



      <div tcSequentialRenderer>
      <form-section-a *tcIfPreviousBlockLoaded></form-section-a>
      <form-section-b *tcIfPreviousBlockLoaded></form-section-b>
      <form-section-c *tcIfPreviousBlockLoaded></form-section-c>
      ...
      <form-section-z *tcIfPreviousBlockLoaded></form-section-z>
      </div>


      .



      @Directive({selector: '[tcSequentialRenderer]'})
      export class SequentialRendererDirective implements AfterViewInit {

      @ContentChildren(IfPreviousBlockLoadedDirective) directives: QueryList<IfPreviousBlockLoadedDirective>;

      ngAfterViewInit() {
      // start from first item
      if (this.directives.length > 0) {
      this.directives.toArray()[0].show();
      }

      let directivesArray = this.directives.toArray();
      for (let i = 1; i < directivesArray.length; i++) {
      directivesArray[i - 1].done.subscribe(status => {
      if (status) {
      directivesArray[i].show();
      }
      });
      }
      }
      }


      .



      @Directive({selector: '[tcIfPreviousBlockLoaded]'})
      export class IfPreviousBlockLoadedDirective {

      private isShown = false;

      public done: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(false);

      constructor(
      private tplref: TemplateRef<any>,
      private vcref: ViewContainerRef
      ) { }

      public show(): void {
      if (!this.isShown) {
      this.vcref.createEmbeddedView(this.tplref);
      this.isShown = true;
      }
      }
      }


      If I can somehow access the associated component from the IfPreviousBlockLoadedDirective this method will work seamlessly.



      Are there any suggestions to fix this, or are there any other ways to achieve this without changing the form-section components?



      NOTE: Form sections can be any angular component.










      share|improve this question














      My problem scenario is as follows,



      I have a page with a large form (+100 inputs). These inputs are divided into sections and those sections are developed as different components (for reusing purposes). So the general layout of the page is something like this,



      <div>
      <form-section-a></form-section-a>
      <form-section-b></form-section-b>
      <form-section-c></form-section-c>
      ...
      <form-section-z></form-section-z>
      </div>


      Each form section will take some time to process because most of the inputs are material select boxes, and necessary data need to be loaded from the REST API and processed.



      In the above shown layout, angular will try to render all form sections at once, hence adding up processing times of each section, which will cause the browser to freeze.



      So, my plan is to load sections one after the other. Is there any recommended way to achieve this?



      I have tried to write a structural directive to load components one after the other. Even though the directive works, there is no way I can know when the component has finished its internal processing work (May be the AfterViewInit hook). The directive looks something like this,



      <div tcSequentialRenderer>
      <form-section-a *tcIfPreviousBlockLoaded></form-section-a>
      <form-section-b *tcIfPreviousBlockLoaded></form-section-b>
      <form-section-c *tcIfPreviousBlockLoaded></form-section-c>
      ...
      <form-section-z *tcIfPreviousBlockLoaded></form-section-z>
      </div>


      .



      @Directive({selector: '[tcSequentialRenderer]'})
      export class SequentialRendererDirective implements AfterViewInit {

      @ContentChildren(IfPreviousBlockLoadedDirective) directives: QueryList<IfPreviousBlockLoadedDirective>;

      ngAfterViewInit() {
      // start from first item
      if (this.directives.length > 0) {
      this.directives.toArray()[0].show();
      }

      let directivesArray = this.directives.toArray();
      for (let i = 1; i < directivesArray.length; i++) {
      directivesArray[i - 1].done.subscribe(status => {
      if (status) {
      directivesArray[i].show();
      }
      });
      }
      }
      }


      .



      @Directive({selector: '[tcIfPreviousBlockLoaded]'})
      export class IfPreviousBlockLoadedDirective {

      private isShown = false;

      public done: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(false);

      constructor(
      private tplref: TemplateRef<any>,
      private vcref: ViewContainerRef
      ) { }

      public show(): void {
      if (!this.isShown) {
      this.vcref.createEmbeddedView(this.tplref);
      this.isShown = true;
      }
      }
      }


      If I can somehow access the associated component from the IfPreviousBlockLoadedDirective this method will work seamlessly.



      Are there any suggestions to fix this, or are there any other ways to achieve this without changing the form-section components?



      NOTE: Form sections can be any angular component.







      angular angular-components angular-dynamic-components angular-component-life-cycle






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 19 '18 at 10:37









      charith.arumapperumacharith.arumapperuma

      202215




      202215
























          3 Answers
          3






          active

          oldest

          votes


















          0














          You're going way too far for so little.



          Use event emitters bound to AfterViewInit hooks :



            <div>
          <form-section-a (viewLoaded)="displaySectionB = true"></form-section-a>
          <form-section-b *ngIf="displaySectionB" (viewLoaded)="displaySectionC = true"></form-section-b>
          </div>


          @Output() viewLoaded = new EventEmitter();
          ngAfterViewInit() { this.viewLoaded.next(true); }


          Because your components are depending on one each other, you will have to explicitly declare the conditions.



          There's more advanced ways of doing that (for instance using arrays), but I'm sure you will find ways to do that on your own !






          share|improve this answer
























          • Yes. That is my last option. But I would prefer not to change any of the existing components since those are being developed in a shared component library.

            – charith.arumapperuma
            Nov 19 '18 at 10:55











          • Well that will be difficult to bind on hook events (which is basically your only option if you want to know when your view has been initialized) ...

            – trichetriche
            Nov 19 '18 at 11:03



















          0














          The best possible solution I can think is to have a following architecture:



          Step-manager (This component will handle stepping into and out of each form section)




          • The step-manager will also provide a service, which will be available
            to all children components.

          • The Step-manager can also have stuff like a progress indicator (Progress-bar)

          • The step-manager can react to a behavior-subject on the service and switch between components/Different templates within a component.


          Service




          • The service can handle all kinds of component interaction.

          • The service will contain a behavior-subject that will be used by all child components to inform the step-manager that either the back button was pressed, or next button was pressed.

          • The service will also have ability to make all service calls for each of the form-input data.


          Child-components




          • The child components can be separate components (Not recommended)

          • They can be divided into different sections (For example: 3 steps of 'Personal Information' can be 1 component, 5 steps of 'Education information' can be 1 component)(I recommend this)

          • Each child component will have different templates embedded, which will be shown/hidden based on boolean values. (All handled by step-manager)


          Please do let me know if this makes sense.






          share|improve this answer































            0














            I think subject is good idea for your requirement. In fact, I have 3 forms in my app, and I used ion-modal-controller there. Simple example below:



            class OneService {
            public formSubject: Subject<Object> = new Subject<Object>();
            }

            class ParentPage {
            constructor(oneService: OneService ) {
            this.oneService.formSubject.subscribe(nextStepComponentName => {
            this.nextStep(nextStepComponentName);
            });
            }
            nextStep(nextStepComponentName) {
            switch nextStepComponentName:
            case 'ChildComponentB':
            //load it
            break;
            default:
            this.cancel();
            }
            }

            class ChildComponentA {
            constructor(oneService: OneService ) {
            }
            save() {
            //do save.subscribe and
            this.oneService.formSubject.next('ChildComponentB');
            }
            }


            after child call subject.next(), then parent know the child finished. Hope it is helpful.






            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%2f53372780%2fhow-can-i-load-angular-components-in-a-page-in-sequence%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              3 Answers
              3






              active

              oldest

              votes








              3 Answers
              3






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              0














              You're going way too far for so little.



              Use event emitters bound to AfterViewInit hooks :



                <div>
              <form-section-a (viewLoaded)="displaySectionB = true"></form-section-a>
              <form-section-b *ngIf="displaySectionB" (viewLoaded)="displaySectionC = true"></form-section-b>
              </div>


              @Output() viewLoaded = new EventEmitter();
              ngAfterViewInit() { this.viewLoaded.next(true); }


              Because your components are depending on one each other, you will have to explicitly declare the conditions.



              There's more advanced ways of doing that (for instance using arrays), but I'm sure you will find ways to do that on your own !






              share|improve this answer
























              • Yes. That is my last option. But I would prefer not to change any of the existing components since those are being developed in a shared component library.

                – charith.arumapperuma
                Nov 19 '18 at 10:55











              • Well that will be difficult to bind on hook events (which is basically your only option if you want to know when your view has been initialized) ...

                – trichetriche
                Nov 19 '18 at 11:03
















              0














              You're going way too far for so little.



              Use event emitters bound to AfterViewInit hooks :



                <div>
              <form-section-a (viewLoaded)="displaySectionB = true"></form-section-a>
              <form-section-b *ngIf="displaySectionB" (viewLoaded)="displaySectionC = true"></form-section-b>
              </div>


              @Output() viewLoaded = new EventEmitter();
              ngAfterViewInit() { this.viewLoaded.next(true); }


              Because your components are depending on one each other, you will have to explicitly declare the conditions.



              There's more advanced ways of doing that (for instance using arrays), but I'm sure you will find ways to do that on your own !






              share|improve this answer
























              • Yes. That is my last option. But I would prefer not to change any of the existing components since those are being developed in a shared component library.

                – charith.arumapperuma
                Nov 19 '18 at 10:55











              • Well that will be difficult to bind on hook events (which is basically your only option if you want to know when your view has been initialized) ...

                – trichetriche
                Nov 19 '18 at 11:03














              0












              0








              0







              You're going way too far for so little.



              Use event emitters bound to AfterViewInit hooks :



                <div>
              <form-section-a (viewLoaded)="displaySectionB = true"></form-section-a>
              <form-section-b *ngIf="displaySectionB" (viewLoaded)="displaySectionC = true"></form-section-b>
              </div>


              @Output() viewLoaded = new EventEmitter();
              ngAfterViewInit() { this.viewLoaded.next(true); }


              Because your components are depending on one each other, you will have to explicitly declare the conditions.



              There's more advanced ways of doing that (for instance using arrays), but I'm sure you will find ways to do that on your own !






              share|improve this answer













              You're going way too far for so little.



              Use event emitters bound to AfterViewInit hooks :



                <div>
              <form-section-a (viewLoaded)="displaySectionB = true"></form-section-a>
              <form-section-b *ngIf="displaySectionB" (viewLoaded)="displaySectionC = true"></form-section-b>
              </div>


              @Output() viewLoaded = new EventEmitter();
              ngAfterViewInit() { this.viewLoaded.next(true); }


              Because your components are depending on one each other, you will have to explicitly declare the conditions.



              There's more advanced ways of doing that (for instance using arrays), but I'm sure you will find ways to do that on your own !







              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Nov 19 '18 at 10:51









              trichetrichetrichetriche

              26k42152




              26k42152













              • Yes. That is my last option. But I would prefer not to change any of the existing components since those are being developed in a shared component library.

                – charith.arumapperuma
                Nov 19 '18 at 10:55











              • Well that will be difficult to bind on hook events (which is basically your only option if you want to know when your view has been initialized) ...

                – trichetriche
                Nov 19 '18 at 11:03



















              • Yes. That is my last option. But I would prefer not to change any of the existing components since those are being developed in a shared component library.

                – charith.arumapperuma
                Nov 19 '18 at 10:55











              • Well that will be difficult to bind on hook events (which is basically your only option if you want to know when your view has been initialized) ...

                – trichetriche
                Nov 19 '18 at 11:03

















              Yes. That is my last option. But I would prefer not to change any of the existing components since those are being developed in a shared component library.

              – charith.arumapperuma
              Nov 19 '18 at 10:55





              Yes. That is my last option. But I would prefer not to change any of the existing components since those are being developed in a shared component library.

              – charith.arumapperuma
              Nov 19 '18 at 10:55













              Well that will be difficult to bind on hook events (which is basically your only option if you want to know when your view has been initialized) ...

              – trichetriche
              Nov 19 '18 at 11:03





              Well that will be difficult to bind on hook events (which is basically your only option if you want to know when your view has been initialized) ...

              – trichetriche
              Nov 19 '18 at 11:03













              0














              The best possible solution I can think is to have a following architecture:



              Step-manager (This component will handle stepping into and out of each form section)




              • The step-manager will also provide a service, which will be available
                to all children components.

              • The Step-manager can also have stuff like a progress indicator (Progress-bar)

              • The step-manager can react to a behavior-subject on the service and switch between components/Different templates within a component.


              Service




              • The service can handle all kinds of component interaction.

              • The service will contain a behavior-subject that will be used by all child components to inform the step-manager that either the back button was pressed, or next button was pressed.

              • The service will also have ability to make all service calls for each of the form-input data.


              Child-components




              • The child components can be separate components (Not recommended)

              • They can be divided into different sections (For example: 3 steps of 'Personal Information' can be 1 component, 5 steps of 'Education information' can be 1 component)(I recommend this)

              • Each child component will have different templates embedded, which will be shown/hidden based on boolean values. (All handled by step-manager)


              Please do let me know if this makes sense.






              share|improve this answer




























                0














                The best possible solution I can think is to have a following architecture:



                Step-manager (This component will handle stepping into and out of each form section)




                • The step-manager will also provide a service, which will be available
                  to all children components.

                • The Step-manager can also have stuff like a progress indicator (Progress-bar)

                • The step-manager can react to a behavior-subject on the service and switch between components/Different templates within a component.


                Service




                • The service can handle all kinds of component interaction.

                • The service will contain a behavior-subject that will be used by all child components to inform the step-manager that either the back button was pressed, or next button was pressed.

                • The service will also have ability to make all service calls for each of the form-input data.


                Child-components




                • The child components can be separate components (Not recommended)

                • They can be divided into different sections (For example: 3 steps of 'Personal Information' can be 1 component, 5 steps of 'Education information' can be 1 component)(I recommend this)

                • Each child component will have different templates embedded, which will be shown/hidden based on boolean values. (All handled by step-manager)


                Please do let me know if this makes sense.






                share|improve this answer


























                  0












                  0








                  0







                  The best possible solution I can think is to have a following architecture:



                  Step-manager (This component will handle stepping into and out of each form section)




                  • The step-manager will also provide a service, which will be available
                    to all children components.

                  • The Step-manager can also have stuff like a progress indicator (Progress-bar)

                  • The step-manager can react to a behavior-subject on the service and switch between components/Different templates within a component.


                  Service




                  • The service can handle all kinds of component interaction.

                  • The service will contain a behavior-subject that will be used by all child components to inform the step-manager that either the back button was pressed, or next button was pressed.

                  • The service will also have ability to make all service calls for each of the form-input data.


                  Child-components




                  • The child components can be separate components (Not recommended)

                  • They can be divided into different sections (For example: 3 steps of 'Personal Information' can be 1 component, 5 steps of 'Education information' can be 1 component)(I recommend this)

                  • Each child component will have different templates embedded, which will be shown/hidden based on boolean values. (All handled by step-manager)


                  Please do let me know if this makes sense.






                  share|improve this answer













                  The best possible solution I can think is to have a following architecture:



                  Step-manager (This component will handle stepping into and out of each form section)




                  • The step-manager will also provide a service, which will be available
                    to all children components.

                  • The Step-manager can also have stuff like a progress indicator (Progress-bar)

                  • The step-manager can react to a behavior-subject on the service and switch between components/Different templates within a component.


                  Service




                  • The service can handle all kinds of component interaction.

                  • The service will contain a behavior-subject that will be used by all child components to inform the step-manager that either the back button was pressed, or next button was pressed.

                  • The service will also have ability to make all service calls for each of the form-input data.


                  Child-components




                  • The child components can be separate components (Not recommended)

                  • They can be divided into different sections (For example: 3 steps of 'Personal Information' can be 1 component, 5 steps of 'Education information' can be 1 component)(I recommend this)

                  • Each child component will have different templates embedded, which will be shown/hidden based on boolean values. (All handled by step-manager)


                  Please do let me know if this makes sense.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 19 '18 at 11:03









                  Vinod BhavnaniVinod Bhavnani

                  1,1061714




                  1,1061714























                      0














                      I think subject is good idea for your requirement. In fact, I have 3 forms in my app, and I used ion-modal-controller there. Simple example below:



                      class OneService {
                      public formSubject: Subject<Object> = new Subject<Object>();
                      }

                      class ParentPage {
                      constructor(oneService: OneService ) {
                      this.oneService.formSubject.subscribe(nextStepComponentName => {
                      this.nextStep(nextStepComponentName);
                      });
                      }
                      nextStep(nextStepComponentName) {
                      switch nextStepComponentName:
                      case 'ChildComponentB':
                      //load it
                      break;
                      default:
                      this.cancel();
                      }
                      }

                      class ChildComponentA {
                      constructor(oneService: OneService ) {
                      }
                      save() {
                      //do save.subscribe and
                      this.oneService.formSubject.next('ChildComponentB');
                      }
                      }


                      after child call subject.next(), then parent know the child finished. Hope it is helpful.






                      share|improve this answer




























                        0














                        I think subject is good idea for your requirement. In fact, I have 3 forms in my app, and I used ion-modal-controller there. Simple example below:



                        class OneService {
                        public formSubject: Subject<Object> = new Subject<Object>();
                        }

                        class ParentPage {
                        constructor(oneService: OneService ) {
                        this.oneService.formSubject.subscribe(nextStepComponentName => {
                        this.nextStep(nextStepComponentName);
                        });
                        }
                        nextStep(nextStepComponentName) {
                        switch nextStepComponentName:
                        case 'ChildComponentB':
                        //load it
                        break;
                        default:
                        this.cancel();
                        }
                        }

                        class ChildComponentA {
                        constructor(oneService: OneService ) {
                        }
                        save() {
                        //do save.subscribe and
                        this.oneService.formSubject.next('ChildComponentB');
                        }
                        }


                        after child call subject.next(), then parent know the child finished. Hope it is helpful.






                        share|improve this answer


























                          0












                          0








                          0







                          I think subject is good idea for your requirement. In fact, I have 3 forms in my app, and I used ion-modal-controller there. Simple example below:



                          class OneService {
                          public formSubject: Subject<Object> = new Subject<Object>();
                          }

                          class ParentPage {
                          constructor(oneService: OneService ) {
                          this.oneService.formSubject.subscribe(nextStepComponentName => {
                          this.nextStep(nextStepComponentName);
                          });
                          }
                          nextStep(nextStepComponentName) {
                          switch nextStepComponentName:
                          case 'ChildComponentB':
                          //load it
                          break;
                          default:
                          this.cancel();
                          }
                          }

                          class ChildComponentA {
                          constructor(oneService: OneService ) {
                          }
                          save() {
                          //do save.subscribe and
                          this.oneService.formSubject.next('ChildComponentB');
                          }
                          }


                          after child call subject.next(), then parent know the child finished. Hope it is helpful.






                          share|improve this answer













                          I think subject is good idea for your requirement. In fact, I have 3 forms in my app, and I used ion-modal-controller there. Simple example below:



                          class OneService {
                          public formSubject: Subject<Object> = new Subject<Object>();
                          }

                          class ParentPage {
                          constructor(oneService: OneService ) {
                          this.oneService.formSubject.subscribe(nextStepComponentName => {
                          this.nextStep(nextStepComponentName);
                          });
                          }
                          nextStep(nextStepComponentName) {
                          switch nextStepComponentName:
                          case 'ChildComponentB':
                          //load it
                          break;
                          default:
                          this.cancel();
                          }
                          }

                          class ChildComponentA {
                          constructor(oneService: OneService ) {
                          }
                          save() {
                          //do save.subscribe and
                          this.oneService.formSubject.next('ChildComponentB');
                          }
                          }


                          after child call subject.next(), then parent know the child finished. Hope it is helpful.







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Nov 19 '18 at 11:08









                          incNickincNick

                          43425




                          43425






























                              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%2f53372780%2fhow-can-i-load-angular-components-in-a-page-in-sequence%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

                              How to change which sound is reproduced for terminal bell?

                              Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents

                              Can I use Tabulator js library in my java Spring + Thymeleaf project?