0

Property 'find' does not exist on type 'HttpEvent'.

logIn(signInForm: FormGroup) {
    console.log('Login', signInForm);
    this._http.get<any>('http://localhost:3000/signUpData', this.signInForm.value).subscribe(result => {
      if (this.id === undefined) { return }
      this._toast.success(this.signUpData, 'Registered Successfully!');
      const userData = result.find((loginData: any) => {
        return loginData.email === this.signInForm.email && loginData.password === this.signInForm.password
      });
      if (this.signUpData) {
        alert('Login Successfully!')
        this.router.navigate(['dashboard']);
      } else {
        alert('User not found!')
      }
    })

  }
vimuth
  • 5,064
  • 33
  • 79
  • 116
  • Have you tried checking what `result` looks like? If so, feel free to share it. – Philipp Meissner Mar 27 '23 at 07:09
  • `_http.get()` doesn't accept data as second attribute. This can also mess up the typings, which can be the cause of your error. – JSON Derulo Mar 27 '23 at 07:11
  • @PhilippMeissner , I am not able to compile the code as I am getting this error :- Property 'find' does not exist on type 'HttpEvent'. Property 'find' does not exist on type 'HttpSentEvent'. 45 const userData = result.find((loginData: any) => { ~~~~ ✖ Failed to compile. – Vaishali Jaiswal Mar 27 '23 at 07:17
  • Please provide more details, can you print the "result"? You can use debugger/break-point before the point where the code breaks or console.log just before it breaks. – sangress Mar 27 '23 at 07:20
  • @sangress , Yes I can print if I dont use find() – Vaishali Jaiswal Mar 27 '23 at 07:22

2 Answers2

0

The error message is indicating that the find() method is not recognized as a valid method on the type HttpEvent<any>. This is because HttpEvent<any> is a generic type that represents an HTTP response from the server and does not have the find() method.

To fix this issue, you need to specify the type of the response object that you are expecting from the server. In this case, it seems like you are expecting an array of loginData objects. So you can change the type of the response object from HttpEvent<any> to loginData[] like this:

this._http.get<loginData[]>('http://localhost:3000/signUpData', this.signInForm.value).subscribe(result => {
Axel
  • 57
  • 1
  • 10
0

It looks like you are trying to send a GET request with a request body. This is not supported by Angular, see Angular HttpClient Get method with body. If you can change the backend implementation, just switch to POST method.

While the specification allows such requests, it's not good practice, that's why some tools like Angular don't support this. See: HTTP GET with request body.

JSON Derulo
  • 9,780
  • 7
  • 39
  • 56