Coder Social home page Coder Social logo

Comments (4)

christopherthielen avatar christopherthielen commented on April 26, 2024 1

Fixed in https://github.com/ui-router/ng1-to-ng2/releases/tag/1.0.15

from angular-hybrid.

Awk34 avatar Awk34 commented on April 26, 2024

Ah. I was wondering about that. I haven't been creating lazy-loaded routes since I haven't seen any examples of how to do it with Webpack.

from angular-hybrid.

samjetski avatar samjetski commented on April 26, 2024

We're still having this issue.

When we use the visualiser, we can see that states declared on any NgModule are not loaded. But when we navigate to an ng1-declared state which uses an ng2 component, all the NgModule-declared states then appear. Can't work out why...

We're using Webpack, no lazy loading.

from angular-hybrid.

christopherthielen avatar christopherthielen commented on April 26, 2024

@samjetski

Both UIRouterModule.forChild() and Ng1ToNg2Module declare an NgModule with stuff in it. However, it doesn't implicitly instantiate anything from those modules. If you never inject anything that depends on the ng2 UI-Router (for example, a component that uses a UIView or uiSref), ng2 DI never instantiates anything from the forChild() module, so the routes don't get registered.

We need to inject something ng2 for UIRouter

Try this:

  • Call deferIntercept() on $urlRouterProvider (tell ui-router not to check url until you're ready)
  • Add a .ready() to your ngUpgrade bootstrap which:
    • Gets UIRouter class for ng2 from the injector
    • Calls listen() and sync() on the $urlRouter
function readyFn(ref: UpgradeAdapterRef) {
     // Causes ng2 ui-router bootstrap to happen
     ref.ng2Injector.get(UIView);  // geta an ng2 class to trigger DI
     let $urlRouter = ref.ng1Injector.get('$urlRouter');
     $urlRouter.listen();
     $urlRouter.sync();
 }
 
upgradeAdapter.bootstrap(document.body, [...]).ready(readyFn);

This is conceptually similar to ng1 inject in a run() block like so:

app.run([ '$uiRouter', function($uiRouter) {} ])

from angular-hybrid.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.