Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
Ask Question
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
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.