I have a component that is subscribed to a subject which is returning employee records and putting them into an array.
importResults: ImportResults[] = [];
constructor(
private _massEmpService: MassEmpService
) {
}
ngOnInit() {
// Subscribe to our subject that lets us know about the added employees
this._massEmpService.importedData.subscribe(obj => {
if (obj) {
// Ensure that we have unique results in our imported data
this.importResults.push(_.uniqBy(obj, 'QID'));
}
});
}
My issue is that each time my button is clicked and this subscription receives data, its pushing the new data along side what is already there instead of ONLY adding records that don't exist.
Here is an example on a single record received (I entered one user name and clicked search)
Here is an example when I add one additional user, leaving the previous one in the search field.
As you can see, the first array is the original search result. The second array contains the first employee AND the new employee.
My expected outcome here is that there is a single array with unique objects. This would mean there should be 2 records from my example since the first employee was searched two times, he shouldnt be pushed or included into the array since that object already exists.
Am i using this lodash function incorrectly? QID is a unique valid key in the object as well (not pictured).

