0

I am working on Angular 7 Application and , I am facing problem on stopping a function to call again ,where function exist in in constructor , which I stop calling again on navigating back to the same component

eg ->

  1. We are in component A
  2. we navigate and go to component B
  3. when we again go to component A , function in constructor should not load

I tried with many ways using Angular rout , but it is not working for me

Testing Anurag
  • 603
  • 4
  • 13
  • 26
  • We you navigate to component B , component A get destroyed and we you go back to A is gone to construct again – Muhammed Albarmavi Mar 04 '19 at 08:38
  • **why do you think** that constructor should not load. – Antoniossss Mar 04 '19 at 08:40
  • Do you wanna stop the constructor (wich would be weird) ? Or do you wanna stop whats happening in the Constructor like webservices ? – Nikolai Kiefer Mar 04 '19 at 08:53
  • @Antoniossss yes – Testing Anurag Mar 04 '19 at 09:21
  • 1
    show your routing file – shubham chhapre Mar 04 '19 at 09:28
  • https://stackoverflow.com/questions/41280471/how-to-implement-routereusestrategy-shoulddetach-for-specific-routes-in-angular – Amrit Mar 04 '19 at 09:38
  • A **Constructor** is a special type of method of a class and it will be automatically invoked when an instance of the class is created. A `class` may contain at least one `constructor` declaration. If a class has no constructor, a constructor is provided automatically. It's used to allocate memory for the objects of the class Having said that, the `constructor` will get executed if the `component` class loads or reloads.Try to execute those functions conditionally ( make use of route `params` or something to identify reload route). – nircraft Mar 04 '19 at 15:21

1 Answers1

0

If I understand you correctly, you have an initialization logic who supposed to happen only once, so about telling us, once perwhat ?

What do this logic ? In fact, we will need more information to help you on the design level.

What are you trying to achieve ?