1
votes

My home.ts

import { Component, ViewChild } from '@angular/core';
import { NavController, Slides } from 'ionic-angular';
import { AngularFireDatabase, AngularFireList } from 'angularfire2/database';
import { EventDetail } from '../../models/event-detail/event-detail.interface';


@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})
export class HomePage {

  @ViewChild('SwipedTabsSlider') SwipedTabsSlider: Slides ;

  SwipedTabsIndicator :any= null;
  tabs:any=[];

  newEventListRef$ : AngularFireList<EventDetail>;
  newEventList$: Observable<EventDetail[]>;

  constructor(public navCtrl: NavController, private database: AngularFireDatabase) {
    this.tabs=["New", "Upcoming"];
    this.newEventListRef$ = this.database.list<EventDetail>('event-list');
    this.newEventList$ = this.newEventListRef$.valueChanges();
  }

my home.html

<ion-content>

<ion-segment class="SwipeTabs">
<ion-segment-button *ngFor='let tab of tabs ; let i = index ' value="IngoreMe" (click)="selectTab(i)"
    [ngClass]='{ "SwipedTabs-activeTab" : ( this.SwipedTabsSlider  && ( this.SwipedTabsSlider.getActiveIndex() === i || (  tabs.length -1 === i&& this.SwipedTabsSlider.isEnd()))) }' >
        {{tab}}
    </ion-segment-button>
 </ion-segment>

  <div id='indicator' class="SwipedTabs-indicatorSegment" [ngStyle]=" 
{'width.%': (100/this.tabs.length)}"></div>

  <ion-slides #SwipedTabsSlider  (ionSlideDrag)="animateIndicator($event)"
  (ionSlideWillChange)="updateIndicatorPosition()"
  (ionSlideDidChange)="updateIndicatorPosition()"
  (pan)="updateIndicatorPosition()"
  [pager]="false">

<ion-slide>

  <ion-list>
    <ion-item *ngFor="let new of newEventList$ | async">
      <h2>{{new.eventName}}</h2>
      <h4>{{new.eventDesc}}</h4>
      <h6>{{new.lat}}</h6>
      <h6>{{new.lgt}}</h6>
    </ion-item>
  </ion-list>

</ion-slide>

<ion-slide>

</ion-slide>

error: TypeError: Object(...) is not a function

i cant seems to display the event list when the problem yet to occur

TypeError: Object(...) is not a function at SwitchMapSubscriber.project (http://localhost:8100/build/vendor.js:77814:76) at SwitchMapSubscriber._next (http://localhost:8100/build/vendor.js:62612:27) at SwitchMapSubscriber.Subscriber.next (http://localhost:8100/build/vendor.js:20750:18) at RefCountSubscriber.Subscriber._next (http://localhost:8100/build/vendor.js:20786:26) at RefCountSubscriber.Subscriber.next (http://localhost:8100/build/vendor.js:20750:18) at Subject.next (http://localhost:8100/build/vendor.js:23237:25) at ConnectableSubscriber.Subscriber._next (http://localhost:8100/build/vendor.js:20786:26) at ConnectableSubscriber.Subscriber.next (http://localhost:8100/build/vendor.js:20750:18) at Notification.observe (http://localhost:8100/build/vendor.js:52585:50) at AsyncAction.DelaySubscriber.dispatch (http://localhost:8100/build/vendor.js:80114:40)

1

1 Answers

1
votes

There a couple of issues. The primary one being you are using = instead of : with newEventListRef$ when attempting to set the type to AngularFireList<EventDetail>. The next issue being the parenthesis () after AngularFireList<EventDetail>. Removing the parenthesis () and replacing the = with : should resolve the issue. I'd also recommend to provide a type to db.list() like this.db.list<EventDetail>('event-detail').

newEventListRef$: AngularFireList<EventDetail>;

Usage example:

import { AngularFireDatabase, AngularFireList } from '@angular/fire/database';
import { Observable } from 'rxjs';

@Component({
  template: `
    <ul>
      <li *ngFor="let item of newEventList$ | async">{{item.someProperty}}</li>
    </ul>
  `
})
export class HomePage {
  newEventListRef$: AngularFireList<EventDetail>;
  newEventList$: Observable<EventDetail[]>;

  constructor(private db: AngularFireDatabase) {
    this.newEventListRef$ = this.db.list<EventDetail>('event-detail');
    this.newEventList$ = this.newEventListRef$.valueChanges();
  }
}

Hopefully that helps!