1

I have input property [visitors]:

<app-visitor-component [visitors]="visitors"></app-visitor-component>

How replace [visitors]="visitors" on async like:

[visitors]="service.currentUser | async"
1
  • 2
    Why you just don't send it as Observable? Commented Mar 9, 2019 at 15:17

3 Answers 3

2

If your service is an Observable you need to use an Elvis operator:

[visitors]="(service | async)?.currentUser"
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, but how to make filter based this notation? I mean when I typing text in input I need to filter (service.currentUser| async)
The first solution is a create method in a component and use a pipe on an observable with a map operator, second is a create filter pipe which maps your property as in the first solution. It's more convenient and friendly for change detection (search in the Google: pure pipes).
1

You could send it as Observable , if not use async as follows

<app-child [visitors]="(service.currentUser| async)">

2 Comments

Thanks, but how to make filter based this notation? I mean when I typing text in input I need to filter (service.currentUser| async)
@OPV you need to pass the observable, then in the child component you need to subcribe to it and filter the values
1

Make the variable you are passing an Observable or Subject<T> or BehaviourSubject<T>

eg.

// some service
public currentUser: Subject<string> = new Subject<string>();

then use like

[visitors]="service.currentUser | async"

Comments

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.