Mission: CRUD ROOKIE
Task: Delete Object With API
this must me a string not a object.
what should I do?
Mission: CRUD ROOKIE
Task: Delete Object With API
Hello, @Farhan007.
Could you please provide the code that you trying to call.
By mistake, I can say that you did not specify the Object ID in the function call.
Best Regards, Nikita.
// persons-list/persons-list.component.ts
import { Component, OnInit } from '@angular/core';
import { PersonsService } from '../persons.service';
@Component({
selector: 'app-persons-list',
templateUrl: './persons-list.component.html',
styleUrls: ['./persons-list.component.css']
})
export class PersonsListComponent implements OnInit {
constructor(private personsService: PersonsService) {
}
ngOnInit() {
this.getpersons();
}
getpersons() {
this.personsService.find().then((Object:any) =>{
this.deletePerson()
})
}
deletePerson() {
this.personsService.delete(Object).then( function (savedObject) {
console.log( 'Object has been removed' );
}).catch(function (error) {
console.log( 'Error removing object ' +
error.message);
throw error;
});
}
}
// persons.service.ts
import { Injectable } from '@angular/core';
import Backendless from 'backendless';
@Injectable({
providedIn: 'root'
})
export class PersonsService {
public persons: Object[] = [];
find() {
return Backendless.Data.of('Person').findFirst()
}
delete(Object: any){
return Backendless.Data.of('Person').remove(Object)
}
}
Instead of ‘Object’ you need to pass the ‘objectId’ value of your object.
Like this:
Backendless.Data.of( "Person" ).remove('251E1D02-3448-4D56-91E3-A6A5F5F9996A')
I also recommend reading our documentation:
https://backendless.com/docs/js/data_basic_search.html