Skip to content

Commit eb4dc1b

Browse files
committed
step 12: refactor to use AsyncPipe in ContactsListComponent
1 parent 9d33118 commit eb4dc1b

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

src/app/contacts-list/contacts-list.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<ul class="collection">
2-
<li class="collection-item avatar" *ngFor="let contact of contacts">
2+
<li class="collection-item avatar" *ngFor="let contact of contacts | async">
33
<a [routerLink]="['/contact', contact.id]">
44
<img [src]="contact.image" alt="" class="circle">
55
<span class="title">{{contact.name}}</span>
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Component, OnInit } from '@angular/core';
2+
import { Observable } from 'rxjs/Observable';
23
import { ContactsService } from '../contacts.service';
34
import { Contact } from '../models/contact';
45

@@ -9,13 +10,12 @@ import { Contact } from '../models/contact';
910
})
1011
export class ContactsListComponent implements OnInit {
1112

12-
contacts: Array<Contact>;
13+
contacts: Observable<Array<Contact>>;
1314

1415
constructor(private contactsService: ContactsService) {}
1516

1617
ngOnInit() {
17-
this.contactsService.getContacts()
18-
.subscribe(contacts => this.contacts = contacts);
18+
this.contacts = this.contactsService.getContacts();
1919
}
2020

2121
}

0 commit comments

Comments
 (0)