PGH
PGH

Reputation: 2204

To check and PUSH the new object to table component in angular

I have 2 components called list & display. The list component will display customers in the dropdown, From the dropdown(dropdown with multiselect) I will PUSH the selected customers to table(material component) present in the display component like this:

enter image description here

Now i have another form in display component itself in order to generate a new customer.From this form i will generate a new customer and i will PUSH this new customer to table like this:

enter image description here

And i will update the generated customer in list component also like this:

enter image description here

But the issue is When i try to PUSH the same customer(Ex Customer 4) from the list component,It should not add the duplicate, but it is adding:

enter image description here

Note:

DEMO

Upvotes: 0

Views: 180

Answers (1)

k.s.
k.s.

Reputation: 3004

You just need to check your array for occurrences.

I've updated your stackblitz example to work for your requirements. I'd advice you not to store your customers inside CustomerIds object, it'll make it a bit easier.

And just blocking the user from adding is also not the best option, add something to notify the user of the error.

Upvotes: 1

Related Questions