Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular2: removeAll() in RethinkDB with Horizon API

I'm pretty new with Angular2, RethinkDB and Horizon API and I'm building a small webapp. In this app I'm trying to delete all objects in a specific table, and therefore I use the fetch() and removeAll() functions from Horizon API. The problem is the following error:

removeAll takes an array as an argument

The Horizon API's documentation is describing that the fetch() method returns an array, and I'm using this array to removeAll() data. Source: https://horizon.io/api/collection/#fetch

this.table.removeAll(this.table.fetch().subscribe(
  result => console.log('Result:', result),
  err => console.error(err),
  () => console.log('Results fetched')
));

When I log the result of this fetch, it's displaying an array of Objects.

Result: [Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object]

I've tried declaring an array earlier and many other things but nothing seems to work. Any idea's?

like image 405
Wouter Vanherck Avatar asked Dec 22 '25 07:12

Wouter Vanherck


1 Answers

You're very close but you're calling removeAll the wrong way. An example would be this:

ClearTable(): void {
    this.table.fetch().subscribe(
      (returnObjects: Object[]) => {
        this.table.removeAll(returnObjects);
      }
    );
}

You can only manipulate the objects when you subscribe to them. Pass them to an array and now you've got the right objects to pass to the removeAll function

like image 171
DGK Avatar answered Dec 23 '25 22:12

DGK