Home

Awesome

<p align="center"> <a href="https://github.com/Celtian/ngx-if-platform" target="blank"><img src="assets/logo.svg?sanitize=true" alt="" width="120"></a> <h1 align="center">NgxIfPlatform</h1> </p>

npm version Package License NPM Downloads Snyk codecov stars forks HitCount

Angular directive for conditional display based on platform

Angular 18 compatible

Here's the demo or stackblitz live preview or codesandbox live preview

🛠️ Install

  1. Use yarn (or npm) to install the package
yarn add ngx-if-platform
  1. Add NgxIfPlatformModule (or specific directive) into your imports
import { NgxIfPlatformModule } from 'ngx-if-platform';

@Component({
  standalone: true,
  imports: [NgxIfPlatformModule /* , ... */],
  // ...
})

or

  import { NgxIfPlatformModule } from 'ngx-if-platform';

  @NgModule({
   // ...
   imports: [
     // ...
     NgxIfPlatformModule
   ]
  })

🚀 Quick start

Example code

<!-- ngxIf -->
<div *ngxIfBrowser>Is browser</div>
<!-- ngxIf can be disabled  -->
<ng-template [ngxIfServer]="true">Is server (disabled)</ng-template>
<!-- ngxIf else statement  -->
<ng-template [ngxIfServer] [ngxIfNotServer]="notServer">Is server</ng-template>
<ng-template #notServer>Not server</ng-template>

Result

  Is browser
  Is server (disabled)
  Not server

🛠️ Options

There are these directives: ngxIfBrowser, ngxIfServer, ngxIfWorkerApp, ngxIfWorkerUi

Directive & attributes

OptionTypeDefaultDescription
[ngxIfBrowser]booleantrueDirective can be disabled
[ngxIfNotBrowser]templateRefnoneTemplateRef used if confition do not match
[ngxIfServer]booleantrueDirective can be disabled
[ngxIfNotServer]templateRefnoneTemplateRef used if confition do not match

🔧 Compatibility

Angularngx-if-platformInstall
>= 183.xyarn add ngx-if-platform
>= 142.xyarn add ngx-if-platform@2
>= 121.xyarn add ngx-if-platform@1
>= 5 < 130.xyarn add ngx-if-platform@0

🪪 License

Copyright © 2021 - 2024 Dominik Hladik

All contents are licensed under the MIT license.