# ngx-if-platform

> Angular directive for repeating HTML element by count

Latest version **4.0.0** (published 2025-05-31) · MIT license · 0 weekly downloads

## Install

```sh
npm install ngx-if-platform
pnpm add ngx-if-platform
yarn add ngx-if-platform
bun add ngx-if-platform
```

## Health

**Score 45/100 (D)** — status: stable.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: stale.

## Facts

| | |
|---|---|
| Version | 4.0.0 |
| Published | 2025-05-31 |
| First published | 2021-10-02 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=20 |
| Dependencies | 1 |
| Unpacked size | 27.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4 |
| Author | Dominik Hladík |
| Maintainers | celtian |
| Keywords | angular, ngx, platform |

## Links

- npm: https://www.npmjs.com/package/ngx-if-platform
- Repository: https://github.com/Celtian/ngx-if-platform
- Issues: https://github.com/Celtian/ngx-if-platform/issues
- npm.io page: https://npm.io/package/ngx-if-platform

## Dependencies (1)

- [tslib](https://npm.io/package/tslib.md) ^2.3.0

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 4.0.0 (latest) — 2025-05-31
- 3.1.1 — 2025-02-15
- 3.1.0 — 2024-11-28
- 3.0.1 — 2024-10-18
- 3.0.0 — 2024-06-02
- 2.0.1 — 2024-02-10
- 2.0.0 — 2023-12-27
- 1.1.0 — 2023-08-13
- 1.0.8 — 2023-03-15
- 1.0.7 — 2022-12-27
- 1.0.6 — 2022-12-10
- 1.0.5 — 2022-05-15
- 1.0.4 — 2022-02-19
- 1.0.1 — 2021-12-06
- 1.0.0 — 2021-12-06
- … 3 more at https://npm.io/package/ngx-if-platform/versions

## README

<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](https://badge.fury.io/js/ngx-if-platform.svg)](https://badge.fury.io/js/ngx-if-platform)
[![Package License](https://img.shields.io/npm/l/ngx-if-platform.svg)](https://www.npmjs.com/ngx-if-platform)
[![NPM Downloads](https://img.shields.io/npm/dm/ngx-if-platform.svg)](https://www.npmjs.com/ngx-if-platform)
[![Snyk](https://snyk.io/advisor/npm-package/ngx-if-platform/badge.svg)](https://snyk.io/advisor/npm-package/ngx-if-platform)
[![codecov](https://codecov.io/gh/Celtian/ngx-if-platform/branch/master/graph/badge.svg?token=1IRUKIKM0D)](https://codecov.io/gh/celtian/ngx-if-platform/)
[![stars](https://badgen.net/github/stars/celtian/ngx-if-platform)](https://github.com/celtian/ngx-if-platform/)
[![forks](https://badgen.net/github/forks/celtian/ngx-if-platform)](https://github.com/celtian/ngx-if-platform/)
[![HitCount](http://hits.dwyl.com/celtian/ngx-if-platform.svg)](http://hits.dwyl.com/celtian/ngx-if-platform)

> Angular directive for conditional display based on platform

> ✓ _Angular 20 compatible_

Here's the [demo](http://celtian.github.io/ngx-if-platform/) or [stackblitz live preview](https://stackblitz.com/edit/ngx-if-platform) or [codesandbox live preview](https://codesandbox.io/s/ngx-if-platform-dgtck)

- Lightweight
- No dependencies!
- Directive way

## 🛠️ Install

1. Use yarn (or npm) to install the package

```terminal
yarn add ngx-if-platform
```

2. Add `NgxIfPlatformModule` (or specific directive) into your `imports`

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

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

or

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

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

## 🚀 Quick start

### Example code

```html
<!-- 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

```code
  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 &copy; 2021 - 2025 [Dominik Hladik](https://github.com/Celtian)

All contents are licensed under the [MIT license].

[mit license]: LICENSE

---
_Source: https://npm.io/package/ngx-if-platform · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
