How to resolve is not defined at Htmlbuttonelement.onclick

Asked

Viewed 4,995 times

0

I have a button in a table that has the following code

<td> <button class="btn btn-primary float-right" onclick="addCart()"><i class="fa fa-shopping-cart"></i> Adicionar ao Carrinho </button> </td>

But it keeps returning the error "Uncaught Referenceerror: addCart is not defined at Htmlbuttonelement.onclick" And that function exists in the code, I don’t know what that problem might be.

  • 3

    But is using Angular???

  • Would not be ng-click?? But put the function signature as well as the element <script> which she is inserted.

  • I tried ng-click tbm unsuccessfully

2 answers

1

If you are using Angular you should give the instruction to click on your button as follows:

<td>
    <button class="btn btn-primary float-right" (click)="addCart()">
        <i class="fa fa-shopping-cart"></i> Adicionar ao Carrinho
    </button>
</td>

And in the Typescript file of your component you should create the function addCart()

This should work. If still giving error, put the complete code of the template and component if possible.

  • I’m using the angular, only in my table I’m using the footable, and for some reason the (click)="addCart()" does not work, so I was looking for other ways to make a button work rs

  • 1

    You can add Typescript code and template to get a better idea and help you?

-2

"Function addCart(){ }" just put this in a javascript that stops giving this error 0.0 If the error continues is because you have a bad connection, maybe to the js file

Browser other questions tagged

You are not signed in. Login or sign up in order to post.