### File

`src/lib/has-write-permission.directive.ts`

### Implements

`OnInit` `OnDestroy`

### Metadata

Selector | `[rxapHasWritePermission]`
Standalone | `true`

### Index

###### Properties

- Public readonly

###### Inputs

- rxapHasWritePermission

###### HostBindings

- readonly

### Constructor

`constructor(authorization: AuthorizationService, cdr: ChangeDetectorRef, scope: string | null)`
Defined in src/lib/has-write-permission.directive.ts:28

Parameters :

Name | Type | Optional
authorization | `AuthorizationService` | No
cdr | `ChangeDetectorRef` | No
scope | `string | null` | No

### Inputs

rxapHasWritePermission
Type : `string`
Required : true
Defined in src/lib/has-write-permission.directive.ts:25

### HostBindings

readonly
Type : `boolean`
Default value : `false`
Defined in src/lib/has-write-permission.directive.ts:27

### Properties

Public readonly
Default value : `false`
Decorators : `@HostBinding('readonly')`
Defined in src/lib/has-write-permission.directive.ts:27

    import {
      ChangeDetectorRef,
      Directive,
      HostBinding,
      Inject,
      Input,
      OnDestroy,
      OnInit,
      Optional,
    } from '@angular/core';
    import { Subscription } from 'rxjs';
    import { tap } from 'rxjs/operators';
    import { AuthorizationService } from './authorization.service';
    import { RXAP_AUTHORIZATION_SCOPE } from './tokens';

    @Directive({
      selector: '[rxapHasWritePermission]',
      standalone: true,
    })
    export class HasWritePermissionDirective implements OnInit, OnDestroy {
      @Input({
        alias: 'rxapHasWritePermission',
        required: true,
      })
      public identifier!: string;
      @HostBinding('readonly')
      public readonly = false;
      private _subscription?: Subscription;

      constructor(
        @Inject(AuthorizationService)
        private readonly authorization: AuthorizationService,
        @Inject(ChangeDetectorRef)
        protected readonly cdr: ChangeDetectorRef,
        @Optional()
        @Inject(RXAP_AUTHORIZATION_SCOPE)
        private readonly scope: string | null = null,
      ) {
      }

      public ngOnInit() {
        this._subscription = this.authorization
                                 .hasPermission$(this.identifier, this.scope || null)
                                 .pipe(
                                   tap((hasPermission) => {
                                     this.readonly = !hasPermission;
                                     this.cdr.markForCheck();
                                   }),
                                 )
                                 .subscribe();
      }

      public ngOnDestroy() {
        this._subscription?.unsubscribe();
      }
    }

# results matching ""

# No results matching ""