-1
  canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> | Promise<boolean> | boolean {
    return new Promise((resolve, reject) => {
        this.securityService.securityActions().subscribe(
            data => {debugger;
            if(data = this.authorized.find(k => k=='AGREEMENTS_VIEW','AGREEMENTS_INSERT_UPDATE')){
                resolve(true);    
            }
                if(data != this.authorized){
                   resolve(false);
                }
            },
            error => {
                Utils.notifyErrors(error, this.notificationsService);

            }
        )
    });
}

I want to set true if data contains some items of "authorized".

Authorized is formed like this:

  authorized = [
        'AGREEMENTS_VIEW',
        'PROSPECTS_VIEW',
        'AGREEMENTS_INSERT_UPDATE',
        'PRODUCTS_INSERT_UPDATE',
        'PROSPECTS_INSERT_UPDATE',
        'DOCUMENTS_VIEW',
        'DOCUMENTS_INSERT_UPDATE',
    ];

So for example set true if data contains 'AGREEMENTS_VIEW'.

Right now if i set 2 value on K it doesnt work

  • That syntax makes no sense, you're passing `'AGREEMENTS_INSERT_UPDATE'` as a second argument to `.find`. This doesn't seem to be a route guard, Angular or even TypeScript problem; you need to clarify what your precise logic for comparing the two arrays (right?) is. – jonrsharpe Aug 13 '18 at 10:29
  • Also please stop using random quote formatting in your posts; use that *when you're quoting something*. – jonrsharpe Aug 13 '18 at 10:30
  • yeah i was trying to find a way to add 2 arguments on .find(). Is that possible? and also, even with 1 "k" says illegal return statement – Francesco Giberti Aug 13 '18 at 10:31
  • **What is the logic?** I suspect that if you could clearly describe the logic in the question, you would be a long way towards explaining it to JavaScript, too. Please give a proper [mcve] and clear context, or you'll just keep asking the same question [over](https://stackoverflow.com/q/51818528/3001761) and [over](https://stackoverflow.com/q/51816933/3001761) and [over](https://stackoverflow.com/q/51767935/3001761) again. – jonrsharpe Aug 13 '18 at 10:32
  • yeah they were from a previous thing i did there, ive removed them – Francesco Giberti Aug 13 '18 at 10:32

2 Answers2

0

Use some, which returns true if the condition is matched.

return arrayOne.some(itemOfArrayOne => arrayTwo.includes(itemOfArrayOne));

You can replace includes with indexOf(XXX) !== -1.

0

It seems you have a syntax error:

data === this.authorized.find(k => k=='AGREEMENTS_VIEW')
//---^^^-----here
Jai
  • 74,255
  • 12
  • 74
  • 103