Created
September 14, 2016 22:02
-
-
Save javebratt/1e3c2eac26252147aa05d7082ea6c222 to your computer and use it in GitHub Desktop.
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
// Is there any performance difference on this 2 approaches: | |
// Injecting on the Page itself: | |
import { Component } from '@angular/core'; | |
import { NavController } from 'ionic-angular'; | |
import { AngularFire, FirebaseListObservable } from 'angularfire2'; | |
@Component({ | |
templateUrl: 'build/pages/home/home.html', | |
}) | |
export class HomePage { | |
public billList: FirebaseListObservable; | |
constructor(public navCtrl: NavController, public af: AngularFire) { | |
this.billList = this.af.database.list('/billList'); | |
} | |
} | |
// Versus using a modular approach and inject through a Provider like this: | |
// Page component | |
import { Component } from '@angular/core'; | |
import { NavController } from 'ionic-angular'; | |
import { BillData } from '../../providers/bill-data/bill-data'; | |
@Component({ | |
templateUrl: 'build/pages/home/home.html', | |
providers: [BillData] | |
}) | |
export class HomePage { | |
public billList: any; | |
constructor(public navCtrl: NavController, public billData: BillData) { | |
this.billList = this.billData.getBillList(); | |
} | |
} | |
// Provider | |
import { Injectable } from '@angular/core'; | |
import { AngularFire, FirebaseListObservable } from 'angularfire2'; | |
@Injectable() | |
export class BillData { | |
public billList: FirebaseListObservable<any>; | |
constructor(public af: AngularFire) {} | |
getBillList(){ | |
return this.af.database.list('/billList'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment