A library for comfortable use of Permissions API in Angular applications
npm install @ng-web-apis/permissions


This is a library to use Permissions API with
Angular.
If you do not have @ng-web-apis/common:
``bash`
npm i @ng-web-apis/common
Now install the package:
`bash`
npm i @ng-web-apis/permissions
Import service in your component:
`ts
import { inject } from "@angular/core";
import { WaPermissionsService } from '@ng-web-apis/permissions';
...
private readonly permissions = inject(WaPermissionsService)
`
Now, use the service to retrieve the
state of the permission in question.
Below is an example of checking the permission to use geolocation:
`ts`
const geolocationStatus$ = this.permissions.state('geolocation');
geolocationStatus$.subscribe((geolocationStatus) => doSomething(geolocationStatus));
Note, that a call to the permissions.state() returns an observable, which will emit new values in case the state fortake(1)
the permission in question changes. If you need to get state just once and stop observing the permission, you can use RxJs operator:
`ts`
geolocationStatus$.pipe(take(1)).subscribe((geolocationStatus) => doSomething(geolocationStatus));
The observable is cold, meaning if there are no active subscriptions, it doesn't track the status of the permission.
The library also provides a tokens to simplify working with
Permissions API:
- WA_PERMISSIONS_SUPPORT returns true if user's browser supports
Permissions API
`ts``
export class Example {
constructor(@Inject(WA_PERMISSIONS_SUPPORT) private readonly permissionsSupport: boolean) {}
}
|
|
|
|
|
| :-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: |
| 79+ | 46+ | 43+ | 16+ |
Other Web APIs for Angular by
@ng-web-apis