Ionic 3 - Sending data to service from component


#1

I am trying to send an object from my component which is from the input of the user to the service I have.

This is my code…

Sample.html

<ion-item>
  <ion-label color="primary">Subject</ion-label>
  <ion-select [(ngModel)]="attendanceSet.subject">
    <ion-option *ngFor="let subject of subjects" [value]="subject.title">{{subject.title}}</ion-option>
  </ion-select>
</ion-item>

<ion-item>
  <ion-label color="primary">Date</ion-label>
  <ion-datetime [(ngModel)]="attendanceSet.date" displayFormat="DDD MMM DD" pickerFormat="YYYY MM DD"></ion-datetime>
</ion-item>

<button ion-button block padding (click)="proceed(attendanceSet)">Proceed</button>

Sample.ts

public attendanceSet = {}

proceed(attendanceSet){
  this.navCtrl.push(CheckAttendancePage, {
    setData: attendanceSet
})

Service

private attendanceListRef: AngularFireList<Attendance>

public setAttendance = {}

constructor(private db: AngularFireDatabase, private events: Events, public navParams: NavParams, private method: CheckAttendancePage){

    this.attendanceListRef = this.db.list<Attendance>('attendance/')

}

addAttendance(attendance: Attendance) {
    return this.attendanceListRef.push(attendance)
}

What I’m trying to do is getting data from the sample.html which I will later use to define the path of the “attendanceListRef” like this “attendance/subject/date”

Is there any proper or alternative way to do this? Thanks!