Angular 5.2 AOT build error Expected 0 arguments, but got 1 when using $event
Asked Answered
Q

3

13

I am capturing output event in method without parameter and it's working fine. but when i try to build AOT --prod getting folloing error.

Expected 0 arguments, but got 1

Html code: SaveSortOrder($event)
backend code: SaveSortOrder() {}
Quadruplex answered 22/2, 2018 at 16:2 Comment(0)
A
31

AOT is very strict. In this case you are passing the value of $event when you call SaveSortOrder, but the method doesn't accept one. Either change the html not to pass $event or add an argument to SaveSortOrder.

Do one of the following:

Html code <button click="SaveSortOrder()" />

backend SaveSortOrder($event: any) { /* ... */ }

Across answered 22/2, 2018 at 16:5 Comment(1)
fantastic answer!Sheepfold
R
1

In the local environment, it doesn't give an error but on the live environment, it gives error so to solve that perform any one of the following fix.

Reason You pas a parameter from HTML but doesn't have a variable in typescript method

Component Html Fix

OR

Component ts file Fix SaveSortOrder($event: any) { }

Roose answered 24/6, 2020 at 11:30 Comment(0)
C
0

The html send a parameter to his function in typescript that not excepeted or vice versa. Html Code

<div (click)="closeSideInfo($event)">

TypeScript

 closeSideInfo() {}

Then, remove a parameter in html or adding it to function in typescript

Convolve answered 5/6, 2020 at 22:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.