angular - using async pipe on observable<Object> and bind it to local variable in html

Discussão em 'Angular' iniciado por Han Che, Dezembro 1, 2024.

  1. Han Che

    Han Che Guest

    Hi I have a observable user$ with a lot of properties (name, title, address...)

    component{
    user$:Observerable<User>;
    constructor(private userService:UserService){
    this.user$ = this.userService.someMethodReturningObservable$()
    }
    }


    Is there a way to use the async pipe in the html template to subscribe to it and bind it to a local variable like this

    <div #user="user$ | async">
    <h3> {{user.name}}
    </div>


    I know can can subscribe to it in the constructor and then unsubscribe in OnLeave/OnDestroy but I was just curious if I could use the async pipe.

    Cheers

    Continue reading...

Compartilhe esta Página