user11352561
user11352561

Reputation: 2637

Angular - error TS2554: Expected 1 arguments, but got 0

I am using Angular-11.

I have this code:

header.component.html:

<a class="btn btn-danger btn-flat float-right" href="javascript:void(0)" (click)='logout()'>Sign out

header.component.ts:

logout($event: MouseEvent){
  // tslint:disable-next-line:no-unused-expression
  $event.preventDefault();
  this.loggedIn = false;
  this.token.remove();
  this.auth.changeAuthStatus(false);
  this.router.navigateByUrl('/login');
  this.notify.info("Logout Succesfully", {timeout:2000});
}

I got this error:

error TS2554: Expected 1 arguments, but got 0

<a class="btn btn-danger btn-flat float-right" href="javascript:void(0)" (click)='logout()'>Sign out

It highlights logout().

How do I resolve this?

Thanks

Upvotes: 1

Views: 1394

Answers (3)

Barış Can Yılmaz
Barış Can Yılmaz

Reputation: 735

Your logout function has MouseEvent parameter and you don't send it in your html file.

Your html template should be

<a class="btn btn-danger btn-flat float-right" href="javascript:void(0)" (click)='logout($event)'>Sign out

Upvotes: 0

Mihai Alexandru-Ionut
Mihai Alexandru-Ionut

Reputation: 48367

You should pass $event object.

(click)='logout($event)'

Upvotes: 1

Ga&#235;l J
Ga&#235;l J

Reputation: 15090

Your logout method is expecting a parameter (event) that you are not providing.

In the template you have to write (click)='logout($event)'.

$event is a variable provided by Angular representing the event.

Upvotes: 1

Related Questions