@Inject(PLATFORM_ID) private platformId code example
Example: @Inject(PLATFORM_ID)private platformId
component.ts
import { Component, Inject } from '@angular/core';
import { PLATFORM_ID } from '@angular/core';
import { isPlatformBrowser } from '@angular/common';
@Component({
selector: 'mySpecial',
templateUrl: './mySpecial.component.html'
})
export class MySpecialComponent {
isBrowser: boolean;
constructor( @Inject(PLATFORM_ID) platformId: Object) {
this.isBrowser = isPlatformBrowser(platformId);
}
}
component.html
<h2>Hello World</h2>
<p>
<md-select *ngIf="isBrowser" placeholder="Favorite food" name="food">
<md-option value="Steak">Steak</md-option>
<md-option value="Pizza">Pizza</md-option>
<md-option value="Tacos">Tacos</md-option>
</md-select>
</p>