Open In App

Angular10 isPlatformServer() Function

In this article, we are going to see what is isPlatformServer in Angular 10 and how to use it.

The isPlatformServer is used to get a platform id that represents a server platform



Syntax:

isPlatformServer(platformId);

NgModule: Module used by isPlatformServer is:



Return Value: returns a Boolean Value stating whether a platform id represents a server platform.

Approach: 

Example 1:




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

Output:

Example 2:




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




<div *ngIf = 'isServer==false'>
  platform id does not represents a server platform.
</div>

Output:

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


Article Tags :