ProductPromotion
Logo

Angular.JS

made by https://0x3d.site

GitHub - nigrosimone/ng-condition: An alternative to `*ngIf; else` directive for simplify conditions into HTML template for Angular application.
An alternative to  `*ngIf; else` directive for simplify conditions into HTML template for Angular application. - nigrosimone/ng-condition
Visit Site

GitHub - nigrosimone/ng-condition: An alternative to  `*ngIf; else` directive for simplify conditions into HTML template for Angular application.

GitHub - nigrosimone/ng-condition: An alternative to `*ngIf; else` directive for simplify conditions into HTML template for Angular application.

NgCondition Build Status Coverage Status NPM version

An alternative to *ngIf; else directive for simplify conditions into HTML template for Angular application.

Description

Sometime multiple *ngIf; else can make html template ugly and complicated to understand, eg.:

<div *ngIf="number <= 5; else majorOf5">
    Number is minor or equal 5
</div>
<ng-template #majorOf5>
    <div *ngIf="number <= 10; else majorOf10">
        Number is minor or equal 10
    </div>    
    <ng-template #majorOf10>
        <div *ngIf="number <= 20; else majorOf20">
            Number is minor or equal 20
        </div>
        <ng-template #majorOf20>
            Number is major of 20
        </ng-template>
    </ng-template>
</ng-template> 

with ng-condition you have a simple if, else if, else block, and the same template become eg.:

<ng-condition>
    <ng-if [condition]="number <= 5">
      Number is minor or equal 5
    </ng-if>
    <ng-else-if [condition]="number <= 10">
      Number is minor or equal 10
    </ng-else-if>
    <ng-else-if [condition]="number <= 20">
      Number is minor or equal 20
    </ng-else-if>
    <ng-else>
      Number is major of 20
    </ng-else>
</ng-condition>

See the stackblitz demo.

Get Started

Step 1: install ng-condition

npm i ng-condition

Step 2: Import NgConditionModule into your app module, eg.:

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';

import { NgConditionModule } from 'ng-condition';

@NgModule({
  declarations: [AppComponent],
  imports: [
    BrowserModule,
    NgConditionModule,
  ],
  providers: [],
  bootstrap: [AppComponent],
  ],
})
export class AppModule { }

Examples

Below there are some examples of use case.

Example: Simple if, else

Example of simple if, else, eg.:

<ng-condition>
    <ng-if [condition]="number % 2 == 0">
      number is even
    </ng-if>
    <ng-else>
      number is odd
    </ng-else>
</ng-condition>

Example: Nested condition

Nested condition, eg.:

<ng-condition>
    <ng-if [condition]="number % 2 == 0">
      number is even
      <ng-condition>
        <ng-if [condition]="number <= 5">
          Number is minor or equal 5
        </ng-if>
        <ng-else>
          Number is major of 5
        </ng-else>
      </ng-condition>
    </ng-if>

    <ng-else>
      number is odd
      <ng-condition>
        <ng-if [condition]="number <= 10">
          Number is minor or equal 10
        </ng-if>
        <ng-else>
          Number is major of 10
        </ng-else>
      </ng-condition>
    </ng-else>
</ng-condition>

Support

This is an open-source project. Star this repository, if you like it, or even donate. Thank you so much!

My other libraries

I have published some other Angular libraries, take a look:

More Resources
to explore the angular.

mail [email protected] to add your project or resources here 🔥.

Related Articles
to learn about angular.

FAQ's
to learn more about Angular JS.

mail [email protected] to add more queries here 🔍.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory