2

This is my .ts file and i don't know why i am getting the error above. The push on the addClick method has a red dotted line beneath it.

I followed a tutorial and it is the same as the guy did it on his tutorial.

import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 
'ionic-angular';
import { AngularFireDatabase , AngularFireObject } 
from 'angularfire2/database';
import { Observable } from 'rxjs';



@IonicPage()
@Component({
selector: 'page-create-quiz',
templateUrl: 'create-quiz.html',
})
export class CreateQuizPage {
tasks : Observable <any> ; 
myInput;

constructor(public db:AngularFireDatabase){
this.tasks = this.db.object('/tasks').valueChanges()
this.tasks .subscribe(data => {
  this.myInput = data;
})
}

addclick(){
this.db.object<any>('/tasks').push(this.myInput);
}



ionViewDidLoad() {
console.log('ionViewDidLoad CreateQuizPage');
}


}

This is my.html file

<ion-header>
<ion-navbar>
<ion-title>Create you quiz here</ion-title>
</ion-navbar>
</ion-header>

<ion-content padding>
<ion-item>
<ion-input [(ngModel)] = "myInput" ></ion-input>


</ion-item>
<button (click)= "addclick()"> Add</button>
</ion-content>
0

1 Answer 1

1

object() is a method inside AngularFireDatabase class:

 object<T>(pathOrRef: PathReference): AngularFireObject<T>  {
  const ref = getRef(this.database, pathOrRef);
  return createObjectReference<T>(ref, this);
 }

https://github.com/angular/angularfire2/blob/master/src/database/database.ts#L37

Since it is of type AngularFireObject then you can use the following methods:

method  

set(value: T)       Replaces the current value in the database with the new value specified as the parameter. This is called a destructive update, because it deletes everything currently in place and saves the new value.
update(value: T)    Updates the current value with in the database with the new value specified as the parameter. This is called a non-destructive update, because it only updates the values specified.
remove()            Deletes all data present at that location. Same as calling set(null).

https://github.com/angular/angularfire2/blob/master/docs/rtdb/objects.md#api-summary

Therefore, there is no push() method.


In your code, it seems you just want to add data, therefore you can use push() that is inside AngularFireList. Example:

const itemsRef = db.list('items');
itemsRef.push({ name: newName });

Read the docs here:

https://github.com/angular/angularfire2/blob/master/docs/rtdb/lists.md

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.