Created
May 31, 2020 16:38
-
-
Save AregSargsyan/1c65e5d5e8ec7a04914050c451548aee to your computer and use it in GitHub Desktop.
asyncPipe.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Component, OnInit, ChangeDetectionStrategy } from '@angular/core'; | |
import { HttpClient } from '@angular/common/http'; | |
import { Observable } from 'rxjs'; | |
import { map, } from 'rxjs/operators'; | |
@Component({ | |
selector: 'app-b', | |
template: `<img [src]="user$|async">`, | |
changeDetection: ChangeDetectionStrategy.OnPush | |
}) | |
export class BComponent implements OnInit { | |
user$: Observable<string> | |
constructor(private http: HttpClient) { } | |
ngOnInit(): void { | |
this.user$ = this.http.get('https://randomuser.me/api/').pipe(map((res:any):string => { | |
return res = res.results[0].picture.medium | |
})) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment