Skip to content

Instantly share code, notes, and snippets.

@P1xt
Created March 14, 2017 02:46
Show Gist options
  • Save P1xt/cbe1160ca04e2028e9db08e47e7f4d1b to your computer and use it in GitHub Desktop.
Save P1xt/cbe1160ca04e2028e9db08e47e7f4d1b to your computer and use it in GitHub Desktop.
Angular 2 - component subscribing to data provided by service
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