TypeError:“在严格模式函数或调用它们的参数对象上,可能无法访问'caller','callee'和'arguments'属性”

时间:2019-02-17 12:00:15

标签: angular typescript

我收到此错误“ TypeError:”在严格模式函数或调用它们的参数对象上可能无法访问'caller','callee'和'arguments'属性“每当我尝试从我在我的诺言中的解决方案。这好几天都工作正常,现在突然不起作用了。我还尝试通过诺言中的决议传递相同的值。导致此错误的函数是:this.authenticateUser (registerForm.value);

我尝试将不同的值添加到功能参数字段不起作用。

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.


1 个答案:

答案 0 :(得分:1)

存在错误或错误键入console.log.arguments(loginData),应为console.log(loginData)

错误是说严格模式下禁止arguments属性。而且Typescript始终会编译为严格模式的Javascript。