Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <ion-item-sliding *ngFor="let list of list" >
- <ion-item>
- <p>An item:
- <strong>{{list.list1}}</strong>
- </p>
- <p>Oooooh is this important:
- <strong>{{list.list2}}</strong>
- </p>
- <p>Another item:
- <strong>{{list.list3}}</strong>
- </p>
- </ion-item>
- <ion-item-options side="left">
- <button ion-button color="danger" (click)="deleteList(list.id)"> // this should be id not key
- <ion-icon name="md-trash">Delete</ion-icon>
- </button>
- </ion-item-options>
- </ion-item-sliding>
- import { EventProvider } from '../../providers/event/event';
- import { User } from 'firebase/app'; // import user from firebase;
- import * as firebase from 'firebase/app';
- @IonicPage()
- export class ListPage {
- /* public list: Array<any>; */
- lists = [];
- authenticatedUser: User; //declare variable authenticatedUser as type User
- constructor(
- public navCtrl: NavController,
- public eventProvider: EventProvider
- ) { firebase.auth().onAuthStateChanged(user => {
- if (user) {
- this.authenticatedUser = user;
- }
- });
- }
- deleteList(key) {
- firebase
- .database()
- .ref(`/userProfile/${this.authenticatedUser.uid}/List/${key}`).remove()
- }
- ionViewDidLoad() {
- this.eventProvider.getlist().on('value', listSnapshot => {
- this.lists = [];
- listSnapshot.forEach(snap => {
- this.lists.push({
- id: snap.key,
- list1: snap.val()
- });
- return false; // why are you returning false dont use it.
- });
- });
- }
- }
Add Comment
Please, Sign In to add comment