Closed congweibai closed 3 years ago
Hi @congweibai,
Thanks for that! Will merge it in, in the future you can make it even simpler though:
Instead of this:
let canPush = true;
this.control.value.forEach((item)=>{
canPush = (item.id !== newVal.id) && canPush
})
if(canPush)
this.control.value.push(newVal);
You could use Array method .every():
let canPush = this.control.value.every(item => item.id != newVal.id)
if(canPush)
this.control.value.push(newVal);
Will merge it in now though. Cheers, Ben
Thanks, Ben. That makes sense to me and I did little research on native array methods. I think this could work as well.
let canNotPush = this.control.value.some(item => item.id != newVal.id)
if(!canNotPush)
this.control.value.push(newVal)
Hi Ben, Currently, user is able to add permission to permission array with same id, so I add a filter to avoid users push the permission with same permission id.
Hopefully, this makes sense to you.
Thank you and have a nice day!
Wyatt