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.

async pipe works different with .? operator after upgrade to RC.5

See original GitHub issue

I’m submitting a … (check one with “x”)

[x ] bug report
[ ] feature request
[ ] support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question

In templates where value is Observable

{{(value|async)?.number}}

Current behavior Cannot read property ‘number’ of null

But when I wrote Pipe with simple value && value.number and changed template

{{value|async|customPipe}}

All works as expected. Sad but I can’t reproduce it in generic project

Expected/desired behavior No error, but when data come then value updated

Please tell us about your environment:

  • Angular version: 2.0.0-rc.5
  • Browser: Chrome 53
  • Language: TypeScript 2.0

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
smyth64commented, Sep 6, 2016

@ericcarraway oh yeah I see… Thanks so much!

image

2reactions
chuckjazcommented, Aug 10, 2016

The issue is the assumption that generating an expression twice will generate the same expression producing the same value. The generated code looks like:

var currVal_0 = jit_interpolate7(1,'Async value: ',
  ((valUnwrapper.unwrap(self._pipe_async_0.transform(self.context.observable)) == null)? 
    null: 
    valUnwrapper.unwrap(self._pipe_async_1.transform(self.context.observable)).value),'')

This observes two values coming from the pipe instead of just the first one. It checks the first for null then assumes the second will be non-null. The solution is to introduce a temporary storing the result of the first invocation. The would result in code like,

var tmp_0;
var currVal_0 = jit_interpolate7(1,'Async value: ',
    ((tmp_0 = valUnwrapper.unwrap(self._pipe_async_0.transform(self.context.observable)) == null)?
      null: 
      tmp_0.value),'')

I will work on introducing the temporary variable.

Read more comments on GitHub >

github_iconTop Results From Across the Web

angular - Use async pipe with "||" operator doesnt work correctly
Assuming that someSubscription$ isn't an Observable<boolean> , you can then perform a strict test to differentiate output . <div *ngIf="( ...
Read more >
AsyncPipe - Angular
The async pipe subscribes to an Observable or Promise and returns the latest value it has emitted. When a new value is emitted,...
Read more >
5 Common Mistakes with RxJS - Bits and Pieces
One of the most commonly used operators is mergeMap . This operator allows you to flatten an inner Observable and will maintain many...
Read more >
How to use the ASYNC PIPE effectively in Angular Templates
You can use the async pipe in Angular to automatically subscribe to and unsubscribe from observables, and display data in the template.
Read more >
Fix list for IBM WebSphere Application Server V8.5
The following is a complete listing of fixes for V8.5 with the most recent fix at ... PH39568, StopServer and serverStatus fails to...
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