question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItĀ collects links to all the places you might be looking at while hunting down a tough bug.

And, if youā€™re still stuck at the end, weā€™re happy to hop on a call to see how we can help out.

AsyncPipe doesn't register identical numbers as a change

See original GitHub issue

šŸž bug or intended?

Description

Hello everyone, Iā€™m trying to figure out as to why my AsyncPipe is not exactly behaving like a basic subscription. I have an external subject to which I next numbers upon. This subject is given to a child-component through the Async pipe, which then displays whatever given in its template.

For this easy test case, I also want to reset that internal @Input() of the child component whenever I want to, to 0. However, when I did reset that internal value to 0, and try to next another number ( the same number as I previously did ), the @Input() setter does not pick up any change coming from the Async subscribed subject. Iā€™m guessing the Async-pipe has some logic built in that covers duplicates? Although, I would think that it would act the same as a subscription on that Subject, because a normal subscription does log every entry, even identical ones.

Unsure if this is a bug, or just something that is intended. Iā€™ve read the documentation and it only says that When a new value is emitted, the async pipe marks the component to be checked for changes., but I was thinking it is mentioning that for the change detection itself? Or is the AsyncPipe simply built to only act whenever the value has changed from the previous one, as sending through objects always triggers it?

Any help is highly appreciated.

šŸ”¬ Minimal Reproduction

Iā€™ve created a StackBlitz, just click on the first button to next 200 for the first time, then click the second button to reset it internally in the child component and then try to do another next of 200.

https://stackblitz.com/edit/angular-xvahxd

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
StevenSerriencommented, Jul 24, 2019

Hi @StevenSerrien , The issue is not with asyncPipe , this is because the way the code is written, on reset you should call next again to update the counter value, which you are missing.

change your reset to

enterData() {
    this.data = Array.from(new Array(10), (x, i) => ({
      id: i,
      name: `Character ${i}`,
    }));
    
     this.count$.next(0);
}

Hi @santoshyadav198613, thanks for your reply. I guess that thatā€™s the issue tho, what if Iā€™m building a library and for the sake of convenience do not want the user that is using the hellocomponent from library to have to manually send a next on its subject to reset it, but rather handle it inside the library component. Seems like a valid usecase, no ?

1reaction
trotylcommented, Jul 24, 2019
Read more comments on GitHub >

github_iconTop Results From Across the Web

Async pipe doesn't display updated observable value
1 Answer 1 ; // SPDX-License-Identifier: Apache-2.0 import { Component ; from '@angular/core'; import ; from 'rxjs'; @ComponentĀ ...
Read more >
The difference between NgDoCheck and AsyncPipe in ...
In this article I'm going to show you how to manually work with change ... the async pipe implementation doesn't perform comparison at...
Read more >
Template type checking - Angular
Overview of template type checkinglink. Just as TypeScript catches type errors in your code, Angular checks the expressions and bindings within theĀ ...
Read more >
Angular Change Detection - How Does It Really Work?
Angular can detect when component data changes, and then automatically ... We can override functions in String or Number if we so want....
Read more >
Explain pure and impure pipe in Angular - GeeksforGeeks
A pure function does not depend on any state, data, or change during the execution. In other words, given the same arguments,Ā ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found