Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to pass two arguments for a method in the HTML template?

This is the method in app.component.ts:

deleteItem(collectionName:string, documentId:string){
    this.firestore.collection(collectionName).doc(documentId).delete();
  }

Trying to use it in app.component.html:

<button type="button" (click)="deleteItem(item.docId : item.colname)">delete</button>

I am receiving the following error message:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Expected 2 arguments, but got 1.

>Solution :

If you are passing two or more arguments – a) they need to be in the right order (ie: passed in the order that the function expects them to be passed in – which in this case is collection name first and then document id) ) and b) they are separated by a comma not a colon.

deleteItem(collectionName:string, documentId:string){
    this.firestore.collection(collectionName).doc(documentId).delete();
  }


<button type="button" (click)="deleteItem(item.colname, item.docId)">delete</button>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading