Created
May 18, 2020 16:31
-
-
Save michaelilyin/2e0d290953dee617192ed7e70697b34d to your computer and use it in GitHub Desktop.
Find an issue and propose decision
This file contains hidden or 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
<span>Total users: {{ (users$ | async).length }}</span> | |
<div *ngFor="let user of users$ | async"> | |
{{ user.firstName }} {{ user.lastName }} | |
</div> |
This file contains hidden or 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 { ChangeDetectionStrategy, Component, OnInit } from '@angular/core'; | |
import {UsersService} from '../users.service'; | |
@Component({ | |
selector: 'hrh-users', | |
templateUrl: './users.component.html', | |
changeDetection: ChangeDetectionStrategy.OnPush | |
}) | |
export class UsersComponent implements OnInit { | |
users$ = this.userService.getUsers(); | |
constructor(private readonly userService: UsersService) {} | |
ngOnInit(): void {} | |
} |
This file contains hidden or 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 {Injectable} from '@angular/core'; | |
import {Observable} from 'rxjs'; | |
import {HttpClient} from '@angular/common/http'; | |
export interface User { | |
firstName: string; | |
lastName: string; | |
} | |
@Injectable({ | |
providedIn: 'root' | |
}) | |
export class UsersService { | |
constructor(private http: HttpClient) {} | |
getUsers(): Observable<User[]> { | |
return this.http.get<User[]>('/users'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment