Angular Nested Comparison Of Objects
Compare selectedNewUser object to res.items object using the emailAddress as key , if match then I want to get or at least log the roles from selectedNewUser that matches the email
Solution 1:
Problem is that, the selectedNewUser
is an Array not a simple Object, you cannot access roles directly from this array selectedNewUser
. you need to pass the index also like this.selectedNewUser[0].roles
, but at a moment you haven't think about the index
of selectedNewUser
. You need to modified the your _transactionUserPageEvent()
method like below
private _transactionUserPageEvent() {
this.isTransactionUserLoading = true;
this.transactionUserTable.data = [];
this._userProfileService.getTeamProfileTableDropdown(
this.accountId,
this.transactionUserTable.pageIndex + 1,
this.transactionUserTable.pageSize,
this.searchTransactionUserInput.nativeElement.value,
this.transactionUserTable.sortParams,
this.transactionUserTable.sortDirs
)
.pipe(
finalize(() => this.isTransactionUserLoading = false)
)
.subscribe({
error: err => this._notificationService.showError(err),
next: res => {
this.transactionUserTable.totalElements = res.totalItemCount;
this.transactionUserTable.data = res.items as unknown as UserProfileDropdownDto[];
this.totalData = res.totalItemCount;
this.currentDisplayedData = res.lastItemOnPage;
console.log("res" , res.items)
if(this.selectedNewUser.length !== 0) {
res.items.forEach(item => {
if(item.emailAddress){
let index = this.selectedNewUser.findIndex(x => x.emailAddress === item.emailAddress); // getting index separately if(index !== -1) {
item.isChecked = true;
this.userSelectedStatus(item);
this.appendUserList(true,item)
//this.transactionRoleEvent(this.selectedNewUser.roles, item.id)this.transactionRoleEvent(this.selectedNewUser[index].roles, item.id) // this will work for you// console.log("itemmmm" , this.selectedNewUser)
}
}
});
}
},
complete: noop
});
}
Hope it may help you
Post a Comment for "Angular Nested Comparison Of Objects"