Skip to content

Instantly share code, notes, and snippets.

@michaelilyin
Created May 18, 2020 16:31
Show Gist options
  • Save michaelilyin/2e0d290953dee617192ed7e70697b34d to your computer and use it in GitHub Desktop.
Save michaelilyin/2e0d290953dee617192ed7e70697b34d to your computer and use it in GitHub Desktop.
Find an issue and propose decision
<span>Total users: {{ (users$ | async).length }}</span>
<div *ngFor="let user of users$ | async">
{{ user.firstName }} {{ user.lastName }}
</div>
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 {}
}
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