Created
March 14, 2017 02:46
-
-
Save P1xt/cbe1160ca04e2028e9db08e47e7f4d1b to your computer and use it in GitHub Desktop.
Angular 2 - component subscribing to data provided by service
This file contains 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 { Component, OnInit } from '@angular/core'; | |
import { Camper } from '../../classes/camper'; | |
import { AllTimeService } from '../../services/all-time.service'; | |
@Component({ | |
selector: 'app-all-time', | |
templateUrl: './all-time.component.html', | |
styleUrls: ['./all-time.component.scss'] | |
}) | |
export class AllTimeComponent implements OnInit { | |
campers: Camper[]; | |
constructor(private allTimeService: AllTimeService) { } | |
ngOnInit() { | |
this.allTimeService.getCampers() | |
.subscribe(campers => this.campers = campers.sort((a,b) => b.alltime - a.alltime )); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment