Implemented hasclaim directive
All checks were successful
FarmMaps.Develop/FarmMapsLib/pipeline/head This commit looks good
All checks were successful
FarmMaps.Develop/FarmMapsLib/pipeline/head This commit looks good
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
import { Directive, ViewContainerRef,TemplateRef,OnInit,Input,OnDestroy } from '@angular/core';
|
||||
import { Store} from '@ngrx/store';
|
||||
import * as appCommonReducer from '../../reducers/app-common.reducer'
|
||||
import { IPackages } from '../../models/package';
|
||||
import { Observable, Subscription } from 'rxjs';
|
||||
import { skip } from 'rxjs/operators';
|
||||
import {OAuthService } from 'angular-oauth2-oidc';
|
||||
import { IUser } from '../../models/user';
|
||||
|
||||
@Directive({
|
||||
selector: '[fm-hasclaim]',
|
||||
})
|
||||
export class HasClaimDirective implements OnInit{
|
||||
@Input('fm-hasclaim') claim:string;
|
||||
|
||||
constructor(private templateRef$: TemplateRef<any>,private viewContainerRef$: ViewContainerRef,private store$: Store<appCommonReducer.State>) { }
|
||||
private user$:Observable<IUser> = this.store$.select(appCommonReducer.SelectGetUser).pipe(skip(1));
|
||||
private hasView = false;
|
||||
ngOnInit() {
|
||||
this.user$.subscribe((user) => {
|
||||
if (user.claims[this.claim]) {
|
||||
this.viewContainerRef$.createEmbeddedView(this.templateRef$);
|
||||
this.hasView=true;
|
||||
} else if (this.hasView) {
|
||||
this.viewContainerRef$.clear();
|
||||
this.hasView = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user