Skip to content

Celtian/ngx-if-platform

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

90 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

NgxIfPlatform

npm version Package License NPM Downloads Snyk codecov stars forks HitCount

Angular directive for conditional display based on platform

โœ“ Angular 20 compatible

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

  • Lightweight
  • No dependencies!
  • Directive way

๐Ÿ› ๏ธ 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

Option Type Default Description
[ngxIfBrowser] boolean true Directive can be disabled
[ngxIfNotBrowser] templateRef none TemplateRef used if confition do not match
[ngxIfServer] boolean true Directive can be disabled
[ngxIfNotServer] templateRef none TemplateRef used if confition do not match

๐Ÿ”ง Compatibility

Angular ngx-if-platform Install
>= 20 4.x yarn add ngx-if-platform
>= 18 3.x yarn add ngx-if-platform@3
>= 14 2.x yarn add ngx-if-platform@2
>= 12 1.x yarn add ngx-if-platform@1
>= 5 < 13 0.x yarn add ngx-if-platform@0

๐Ÿชช License

Copyright ยฉ 2021 - 2025 Dominik Hladik

All contents are licensed under the MIT license.

About

Directive for conditional display based on platform

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Packages