This error is related to the lodash.I have added the _.intersection function here,but have no idea what is causing the error.Any help would be appreciated.
import { Directive, OnDestroy, TemplateRef, ViewContainerRef,Input } from "@angular/core";
import { Subscription } from "rxjs";
import { User } from "./model/user";
import { AuthService } from "./services/auth.service";
import * as _ from "lodash";
@Directive({
selector:'[AllowRbac]'
})
export class rbacDirective implements OnDestroy{
userInfo:User;
roles:string[];
sub:Subscription
constructor(private tempRef:TemplateRef<any>,private ViewContainer:ViewContainerRef,
private authService:AuthService){
this.sub=this.authService.user$.subscribe(res=>{
this.userInfo=res
})
}
//to fetch
@Input()set AllowRbac(roles:string[]){
this.roles=roles;
this.showAdminUI()
}
showAdminUI(){
if(!this.roles ||this.roles.length===0|| !this.userInfo){
this.ViewContainer.clear();
return
}
const roles=_.intersection(this.roles,this.userInfo.roles).length > 0
if(roles){
this.ViewContainer.createEmbeddedView(this.tempRef)
}
else{
this.ViewContainer.clear()
}
}
ngOnDestroy() {
this.sub.unsubscribe()
}
}
This is a directive to activate role based Authentication for particular users.To hide UI material depending upon the user logged in example admin or normal user
CodePudding user response:
I have found one solution as below: It's work!
"@types/lodash": "4.14.149",
Thanks ABaranchugov Replay :reference