5

I am getting this error " TypeError: "'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them " Whenever I try to call a function from my resolution in my promise. This was working perfectly fine for multiple days and now all of a sudden it doesnt work. I also tried passing the same values through the resolution in the promise. The function that is causing this error is: this.authenticateUser(registerForm.value);

I have tried adding different values to the function parameter field doesn't work. The

import { NgForm } from '@angular/forms';
import { Router } from '@angular/router';
import { HttpClient, HttpHeaders } from '@angular/common/http';

import { NotificationService } from '../notification/notification.service';
import { UserInterface } from 'src/app/models';

@Injectable({
  providedIn: 'root'
})
export class UserService {

  constructor(
    private httpClient: HttpClient,
    private router: Router,
    private notificationService: NotificationService,
  ) { }


  registerUser(registerForm: NgForm){
    console.log(registerForm.value)
      if( registerForm.value.email && registerForm.value.userName 
          && registerForm.value.firstName && registerForm.value.lastName 
          && registerForm.value.password && registerForm.value.confirmPassword
           ){

            if( registerForm.value.password === registerForm.value.confirmPassword ){

                this.httpClient.post(window.location.protocol + '//' + window.location.hostname + ':3000/register', registerForm.value)
                .toPromise()
                .then(
                  (res) => { 
                    this.authenticateUser(registerForm.value); 
                  }
                ) .catch((err) => { console.log(err); this.notificationService.addNotification(err); })

            } else { this.notificationService.addNotification('Password\'s Do Not Match'); }

      } else { this.notificationService.addNotification('Fill In All Fields'); }
  }

  loginUser(loginForm: NgForm) {
    if( loginForm.value.email && loginForm.value.password) {
      this.authenticateUser(loginForm.value);
    } else {
      this.notificationService.addNotification("Fill In All Field\'s");
    }
  }

  authenticateUser(loginData) {
    console.log.arguments(loginData);
    this.httpClient.post(window.location.protocol + "//" + window.location.hostname + ":3000/login", loginData)
      .toPromise()
      .then(
        (res: UserInterface) => { 
          localStorage.setItem('token', res.token);
          this.notificationService.addNotification('Login Successful');
          this.router.navigate((['/dashboard'])); 
        }
      )
      .catch((err) => { this.notificationService.addNotification(err); console.log(err);})
  }

  isLoggedIn() {

  }

} ```

Just trying to run this function in the resolution of this promise.


Malikiah
  • 149
  • 2
  • 2
  • 13

1 Answers1

6

There is an error or mistype console.log.arguments(loginData) which should be console.log(loginData)

The error is saying arguments property is forbidden in strict mode. And Typescript always compiles to strict mode Javascript.

Nurbol Alpysbayev
  • 19,522
  • 3
  • 54
  • 89