Code Monkey home page Code Monkey logo

Comments (3)

Airblader avatar Airblader commented on July 23, 2024 1

Thanks for reporting this and, importantly, providing a StackBlitz! I will take a closer look and a more detailed reply later on, but if you need a way to make this work quickly, this is it:

    this.paramGroupValues$ = defer(() => this.paramGroup.valueChanges.pipe(
      startWith(this.paramGroup.value),
      takeUntil(this.ngUnsubscribe)
    ));

from ngqp.

steinsag avatar steinsag commented on July 23, 2024

I can confirm this work-around resolves the issue!

from ngqp.

Airblader avatar Airblader commented on July 23, 2024

So to explain a bit further, in case it isn't clear now anyway, the difference is essentially the timing of when paramGroup.value is evaluated. In

this.paramGroupValues$ = this.paramGroup.valueChanges.pipe(
  startWith(this.paramGroup.value),
  takeUntil(this.ngUnsubscribe)
);

this happens when the observable is created, not when it is subscribed. At this point ngqp has had no time to synchronize the value from the URL, of course, and thus the value is null. Wrapping this into defer we can make this evaluation "lazy" such that it occurs when the observable is subscribed, which is what we want: upon subscription we track changes, but start once initially with the current value. This is essentially the same as if valueChanges was a ReplaySubject(1) instead of a Subject.

The fact that I posted this wrong in #72 was just an oversight, thanks for correcting it there. :-) I'll also update my comment there afterwards.

All that being said, this does still behave as intended, and I still think changing the semantic of valueChanges isn't ideal and would rather lean towards the idea of adding a value$ observable which is replayed. I've opened #177 for that (and will in turn close this issue).

from ngqp.

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.