Skip to content

Instantly share code, notes, and snippets.

@AregSargsyan
Created May 31, 2020 16:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AregSargsyan/1c65e5d5e8ec7a04914050c451548aee to your computer and use it in GitHub Desktop.
Save AregSargsyan/1c65e5d5e8ec7a04914050c451548aee to your computer and use it in GitHub Desktop.
asyncPipe.ts
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