import { Component } from '@angular/core' ; import { IonicPage , NavController , NavParams } from 'ionic-angular' ; import { AngularFireDatabase , FirebaseObjectObservable } from 'angularfire2/database' ; import { Subscription } from 'rxjs/Subscription' ; import { ShoppingItem } from './../../models/shopping-item/shopping-item.interface' ; @ Component ( { selector : 'page-edit-shopping-item' , templateUrl : 'edit-shopping-item.html' , } ) export class EditShoppingItemPage { shoppingItemSubscription : Subscription ; shoppingItemRef$ : FirebaseObjectObservable < ShoppingItem > ; shoppingItem = { } as ShoppingItem ; constructor ( public navCtrl , public navParams , private database ) { const shoppingItemId = this . navParams . get ( 'shoppingItemId' ) ; console . log ( shoppingItemId ) ; this . shoppingItemRef$ = this . database . object ( `shopping-list/${ shoppingItemId }` ) ; this . shoppingItemSubscription = this . shoppingItemRef$ . subscribe ( shoppingItem => this . shoppingItem = shoppingItem ) ; } editShoppingItem ( shoppingItem ) { this . shoppingItemRef$ . update ( shoppingItem ) ; this . navCtrl . pop ( ) ; } ionViewWillLeave ( ) { this . shoppingItemSubscription . unsubscribe ( ) ; } }