npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ng-condition

v17.0.1

Published

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

Downloads

24

Readme

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: