0

How can I show only the value 100 in the div below?

<div> {{uploadProgress | async | json}} </div>

The current value shown is:

[ { "filename": "Mailman-Linux.jpg", "progress": 100 } ]

Below my interface from .ts file:

interface IUploadProgress {
  filename: string;
  progress: number;
}
2
  • What about <div> {{uploadProgress.progress}} </div>? Commented Dec 13, 2018 at 15:28
  • no, nothing shows when I do that, also progress is not available to uploadProgress in intellisense in the typescript Commented Dec 13, 2018 at 15:37

1 Answer 1

1

This uploadProgress | async gets the objects of the stream.

After the AsyncPipe it will probably print out [Object object]

Since this is now an object you can simple get the progress attribute like any other object.

Result should look like this:

  <div> {{(uploadProgress | async).progress}} </div>

Additionaly when the observable you have is not an BehaviourSubject then you might want to add a safe navigation with ? after the Asyncpipe to prevent undefined errors:

  <div> {{(uploadProgress | async)?.progress}} </div>

As ShamPooSham correctly mentions, it seems the result is an array. Therefore the answer should look like this:

   <div> {{(uploadProgress | async)[0]?.progress}} </div>
Sign up to request clarification or add additional context in comments.

4 Comments

It seems as the result is an array, so if OP just wants the first value you should add a 0-index
sorry but {{(uploadProgress | async).progress} with or without the ? still doesn't show anything
now returns this error: Parser Error: Conditional expression (uploadProgress | async)?[0].progress requires all 3 expressions at the end of the expression [ {{(uploadProgress | async)?[0].progress}} ]
DarkW1nter ok my bad the ? should be after the index

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.