Angular 2 Cheat Sheet: by Via
Angular 2 Cheat Sheet: by Via
Binding Pipes
Lifecycle Hooks
</li> })
</ul> export class CustomerComponent {
Service
//Example: customer.service.ts
import { HttpModule } from '@angular/http'
@Injectable()
export class CustomerService {
constructor(private http: Http) { }
getCustomers() {
return this.http.get('api/customers')
.map((response: Response) =>
<Customer[]>response.json().data)
.catch(this.handleError);
}
private handleError(error: Response) {
console.error(error);
return Observable.throw(error.json().error ||
'Service error');
}