Skip to content
Related Articles

Related Articles

Improve Article

Angular 10 isPlatformWorkerUi API

  • Last Updated : 14 Jun, 2021

In this article, we are going to see what is isPlatformWorkerUi in Angular 10 and how to use it. The isPlatformWorkerUi API is used to get a platform id that represents a web worker UI platform.

Syntax:

isPlatformWorkerUi( platformId );

NgModule: Module used by isPlatformWorkerUi is:

  • CommonModule

Return Value: It returns a Boolean Value stating whether a platform id represents a web worker UI platform.

 



Approach: 

  • Create an angular app that to be used.
  • Import isPlatformWorkerUi 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 { isPlatformWorkerApp } from '@angular/common';
  
@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: [ './app.component.css' ]
})
export class AppComponent  {
  isWorkerApp: boolean;
  
  constructor( @Inject(PLATFORM_ID) platformId: Object) {
    this.isWorkerApp = isPlatformWorkerApp(platformId);
    console.log(this.isWorkerApp);
  }
}

Output:

Example 2:

app.component.ts




import { Component, Inject } from '@angular/core';
import { PLATFORM_ID } from '@angular/core';
import { isPlatformWorkerApp } from '@angular/common';
  
@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: [ './app.component.css' ]
})
export class AppComponent  {
  isWorkerApp: boolean;
  
  constructor( @Inject(PLATFORM_ID) platformId: Object) {
    this.isWorkerApp = isPlatformWorkerApp(platformId);
  }
}

app.component.html




<div *ngIf = 'isWorkerApp==false'>
    platform id does not represents a web worker UI platform.
</div>

Output:

Reference: https://angular.io/api/common/isPlatformWorkerUi




My Personal Notes arrow_drop_up
Recommended Articles
Page :