scrimba
Build Your First Angular app
Angular Services and Http - Using a SorterService
Go Pro!Bootcamp

Bootcamp

Study group

Collaborate with peers in your dedicated #study-group channel.

Code reviews

Submit projects for review using the /review command in your #code-reviews channel

Angular Services and Http - Using a SorterService
AboutCommentsNotes
Angular Services and Http - Using a SorterService
Expand for more info
src
app
customers
customers.component.ts
run
preview
console
import { Component, OnInit } from '@angular/core';

import { DataService } from '../core/data.service';
import { ICustomer } from '../shared/interfaces';

@Component({
selector: 'app-customers',
templateUrl: './customers.component.html'
})
export class CustomersComponent implements OnInit {
title: string;
people: any[];

constructor(private dataService: DataService) {}

ngOnInit() {
this.title = 'Customers';
this.dataService.getCustomers()
.subscribe((customers: ICustomer[]) => this.people = customers);
// this.people = [
// { id: 1, name: 'john Doe', city: 'Phoenix', orderTotal: 9.99, customerSince: new Date(2014, 7, 10) },
// { id: 2, name: 'Jane Doe', city: 'Chandler', orderTotal: 19.99, customerSince: new Date(2017, 2, 22)},
// { id: 3, name: 'Michelle Thomas', city: 'Seattle', orderTotal: 99.99, customerSince: new Date(2002, 10, 31)},
// { id: 4, name: 'Jim Thomas', city: 'New York', orderTotal: 599.99, customerSince: new Date(2002, 10, 31)},
// ];
}
}
Console
"Angular is running in the development mode. Call enableProdMode() to enable the production mode."
,
customers
-2:34