Last active
January 16, 2017 11:53
-
-
Save vigohe/cedbf896503255d3babb7ebbe1ceb934 to your computer and use it in GitHub Desktop.
Example for http://stackoverflow.com/questions/41659368/angularfire2-access-data-after-retrieve-it/41663265#41663265
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 } from '@angular/core'; | |
import { NavController, NavParams } from 'ionic-angular'; | |
import { MyService } from '../../providers/my-service'; | |
import { AnotherPage } from '../another-page/another'; | |
import 'rxjs/add/operator/filter'; | |
/* | |
Generated class for the MyPage page. | |
See http://ionicframework.com/docs/v2/components/#navigation for more info on | |
Ionic pages and navigation. | |
*/ | |
@Component({ | |
selector: 'page-my-page', | |
templateUrl: 'my-page.html' | |
}) | |
export class MyPage { | |
constructor( | |
public navCtrl: NavController, | |
public navParams: NavParams, | |
private _myService : MyService) {} | |
ionViewDidLoad() { | |
console.log('ionViewDidLoad MyPagePage'); | |
// I JUST WANT TO CHANGE TO ANOTHER PAGE WHEN reg_boolean IT's TRUE | |
this._myService.getRegBoolean().filter(regBoolean => regBoolean === true) | |
.subscribe( () => this.navCtrl.push(AnotherPage)); | |
} | |
} |
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 { Injectable } from '@angular/core'; | |
import 'rxjs/add/operator/map'; | |
import {Observable} from "rxjs"; | |
import {AngularFire} from "angularfire2"; | |
/* | |
Generated class for the MyService provider. | |
See https://angular.io/docs/ts/latest/guide/dependency-injection.html | |
for more info on providers and Angular 2 DI. | |
*/ | |
@Injectable() | |
export class MyService { | |
constructor(private af : AngularFire) { | |
console.log('Hello MyService Provider'); | |
} | |
getRegBoolean() : Observable<boolean> { | |
return this.af.database.list('/users/1qfcMAQnglX9jsW5GdLpPko1HqE2', { preserveSnapshot: true}) | |
.map(snapshots=>{ | |
snapshots.forEach(snapshot => { | |
if(snapshot.key=="reg_boolean"){ | |
return snapshot.val(); | |
} | |
}); | |
return false; | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment