Getting the data from the list to an AlertController


#1

Hai friends. I am new to Ionic development and I’m trying to implement an ecommerce app. So I have a list of items wrapped around *ngFor and I implemented ‘onLongClick()’ function which triggers an AlertControllerlist

onLongClick() function:
onLongClick

In the ‘onLongClick()’ when add button is clicked i want to get the 4 input fields plus the details of the item which i’m pressing, to be able to save to storage in the application.

I am having no luck in getting the selected item to the onLongClick function (from there i can use all the required data to be able to save to local storage). I am having trouble figuring out which parameters or data types I should pass in the function. please help.


#2

You should be able to do this in your template:

(press)="onLongClick(item)"

Then in your controller:
onLongClick(item: YourItemType)


#3

So I altered my template, and the ‘item’ contains an array of values. In my controller I tried to put onLongClick(item : array[])
this does not seem correct as I’m getting error in the editor itself. Please correct me


#4

If item represents an array, how are you able to do: item.image, item.price, and item.name in your template?

Would it be possible to see your data layout?


#5

Hello @sam1408, can you please share the result of console.log(data)?


#6

actually I solved it…I only needed to pass ‘item’ to the function ie, onLongClick(item) and I was able to retrieve the items in the function.


#7

@andreven

I passed 1 in every field and this is the log data:

{“length”:“1”,“width”:“1”,“thickness”:“1”,“quantity”:“1”}