Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

$state.go init the component twice #25

Closed
marcpearson opened this issue Dec 2, 2016 · 12 comments
Closed

$state.go init the component twice #25

marcpearson opened this issue Dec 2, 2016 · 12 comments

Comments

@marcpearson
Copy link

I want to migrate my ui-router Angular 1 application with ngUpgrade and ui-router-ng1-to-ng2

I have a angular 1 state define with a ES6 class component using the ng1-to-ng2 component way

$stateProvider
.state( "accounting/transactions", {
    url: "accounting/transactions",
    parent: "app",
    views: {
      "main": {
        component: AccountingListComponent
      }
    },
    data: {
      pageTitle: "Accounting transactions",
      pageSection: "Accounting",
      pageName: "Transactions"
     }
  })

When calling the state like this from a Angular 2 component:

this.uiRouter.stateService.go("accounting/transactions", null, {reload: true});

or like this from an Angular 1 component

$state.go("accounting/transactions", null, {reload: true});

I can see that my component is call twice because the ngOnInit output twice in the console

FYI, the application use a "app" view has parent and a child "main" view

@BenevidesLecontes
Copy link

@christopherthielen i'm having this issue as well, it seems that this issue old.

@marcpearson
Copy link
Author

@christopherthielen Could you please take a look at this bug. Maybe is not a real one but i can't find a solution. I tried to use the example for checking if ngOnInit will be call twice but the example didn't work.

I can't migrate my application because of this bug. Thanks !!!

@christopherthielen
Copy link
Member

If a reproduction is posted I can try to fix it!

@marcpearson
Copy link
Author

marcpearson commented Aug 21, 2017

(Excuse my english, i'm a french speaker)

I tried to reproduce the bug first within your example code but the example didn't start. (Missing dependencies, no webpack config...) Maybe you could try by yourself with an onNgInit function inside a NG2 controller in your example. Call your NG2 route component with $state.go like i said in the initial post and console something. You'll see 2 output in the browser console.

If you prefer to fix the example code, i could try by myself first to reproduce the bug

Or tell me what i need to give you to help debugging

thanks

@marcpearson
Copy link
Author

Do you have some news about this issue ?

@christopherthielen
Copy link
Member

@marcpearson The example code should work now.

git clone https://github.com/ui-router/angular-hybrid.git
cd angular-hybrid/example
npm install
npm start

I added the ngOnInit() to the routed angular 2 component and it only is triggered once. How can I reproduce the behavior you reported? Have you tried enabling trace? router.trace.enable(1)

@BenevidesLecontes
Copy link

@christopherthielen i have trace enabled it shows only one transition, but suddenly my components init twice, all of them. I'm living with that for now, until i migrate all my app to angular. I don't know how to reproduce too.

@christopherthielen
Copy link
Member

@BenevidesLecontes I'd like to get the bottom of this. Would you be able to share your repository with me? I could sign an NDA if needed.

@BenevidesLecontes
Copy link

@christopherthielen i'll try to eject a module from my app and share with you. Thanks for your effort.

@fxuniverse
Copy link

Also experiencing this. Only when navigating between states passed into UIRouterModule.forChild components defined within are initialized twice, breaking our application. Removing lazyloading does not seem to make a difference, same behavior when module is imported normally. Will appreciate any hints

@christopherthielen
Copy link
Member

If a reproduction is posted I can try to fix it!

@christopherthielen
Copy link
Member

Closing because I have no way to reproduce this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants