Angular 10 isPlatformWorkerApp API
In this article, we are going to see what is isPlatformWorkerApp in Angular 10 and how to use it. The isPlatformWorkerApp API is used to get a platform id that represents a worker app platform.
Syntax:
isPlatformWorkerApp( platformId );
NgModule: Module used by isPlatformWorkerApp is:
- CommonModule
Return Value: It returns a Boolean Value stating whether a platform id represents a worker app platform.
Approach:
- Create an Angular app that to be used.
- Import isPlatformWorkerApp from @angular/core to the project.
- In app.component.ts define the object which holds the Boolean value.
- Serve the angular app using ng serve to see the output.
Example 1:
app.component.ts
import { Component, Inject } from '@angular/core' ; import { PLATFORM_ID } from '@angular/core' ; import { isPlatformWorkerUi } from '@angular/common' ; @Component({ selector: 'app-root' , templateUrl: './app.component.html' , styleUrls: [ './app.component.css' ] }) export class AppComponent { isWorker: boolean; constructor( @Inject(PLATFORM_ID) platformId: Object) { this .isWorker = isPlatformWorkerUi(platformId); console.log( this .isWorker); } } |
Output:
Example 2:
app.component.ts
import { Component, Inject } from '@angular/core' ; import { PLATFORM_ID } from '@angular/core' ; import { isPlatformWorkerUi } from '@angular/common' ; @Component({ selector: 'app-root' , templateUrl: './app.component.html' , styleUrls: [ './app.component.css' ] }) export class AppComponent { isWorker: boolean; constructor( @Inject(PLATFORM_ID) platformId: Object) { this .isWorker = isPlatformWorkerUi(platformId); } } |
app.component.html
< div * ngIf = 'isWorker==false' > platform id does not represents a web worker UI platform. </ div > |
Output:
Reference: https://angular.io/api/common/isPlatformWorkerApp
Please Login to comment...