so hyun
so hyun

Reputation: 47

Property does not exist on type 'Component'

I am new to angular and I want to delete a machine but I get an error in the console :

HttpErrorResponse {headers: HttpHeaders, status: 400, statusText: "Bad Request", url: "http://localhost:3001/machines/delete", ok: false, …}

I don't know how to solve it. that's my component code:

constructor (MachinesService: MachinesService, private toastr: 
ToastrService) {
MachinesService.getMachines().subscribe(
    res => {
          console.log(res);
          this.machines = res;
    },

    err => {
          console.log(err);
    }
  );

    }

       delete(id) {
    this.MachinesService.deleteMachine(id).subscribe();
  }

and my machinesService.ts :

 deleteMachine(id): Observable<any> {
 return this.http.post(environment.apiUrl + '/machines/delete', id);

I have already worked with the same code and it worked well but I don't know what is the problem now. NB : it work in the backend.

Upvotes: 0

Views: 1206

Answers (1)

JB Nizet
JB Nizet

Reputation: 692043

You forgot private before the constructor argument. That's what also makes it a property.

And please, don't name the variable the same way as the type. Use a lowercase first character for variables.

Upvotes: 1

Related Questions