# ng-elif

> if/elif/else directives for AngularJS

Latest version **0.1.4** (published 2015-11-08) · MIT license · 0 weekly downloads

## Install

```sh
npm install ng-elif
pnpm add ng-elif
yarn add ng-elif
bun add ng-elif
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.4 |
| Published | 2015-11-08 |
| First published | 2015-11-08 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 60 |
| Author | Zach Snow |
| Maintainers | zachsnow |
| Keywords | ng-elif |

## Links

- npm: https://www.npmjs.com/package/ng-elif
- Repository: https://github.com/zachsnow/ng-elif
- Issues: https://github.com/zachsnow/ng-elif/issues
- npm.io page: https://npm.io/package/ng-elif

## Recent versions

- 0.1.4 (latest) — 2015-11-08

## README

# ng-elif

A simple collection of control flow directives: `ng-if`, `ng-else-if`, and `ng-else`.

All directives support animations via `$animate`. `ng-if` can be used on the same element as `ng-repeat`,
just like the "real" `ng-if` that it overrides. The primary caveat is that a given if/else-if/else construct
must exist in the same AngularJS scope (hence it doesn't make sense to say that either
`ng-else-if` or `ng-else` work with `ng-repeat`, as `ng-repeat` introduces a new
scope -- obviously you can use it *within* an `ng-repeat`, or any other directive). 
Similarly, while using an `ng-if` on an `ng-include` is supported, note that
`ng-include` introduces a new scope, so that the `ng-if` is actually not on
the same scope as it would appear based solely on the structure of the DOM.  This
means that the following won't work because, despite appearances,
`ng-if` and `ng-else` are actually in *sibling* scopes:

```html
  <div ng-if="someTest" ng-include="'someTemplate'"></div>
  <div ng-else="someTest" ng-include="'someOtherTemplate'"></div>
```

Check out a [live demo](http://plnkr.co/edit/XSPP3jZL8eehu9G750ME?p=preview).

## Dependencies

1. AngularJS.

## Installation

* Load `elif.js`.

* Add `elif` as a dependency to your angular module.

```javascript
  angular.module('yourModule', [
    // ... other dependencies ...
    'elif'
  ]);
```

* Use `ng-if`, `ng-else-if`, and `ng-else` in your templates.  You can also
  use `ng-elif` as an alias for `ng-else-if` if you prefer.

## Example

```html
  <div ng-if="someCondition">
    ...
  </div>
  <p>
    Some random junk in the middle.
  </p>
  <div ng-else-if="someOther && condition">
    ...
  </div>
  <div ng-else-if="moreConditions">
    ...
  </div>
  <div ng-else>
    ...
  </div>
  
  <p>
    More nonsense.
  </p>
  
  <h1 ng-if="anotherIfElse">...</h1>
  <h1 ng-elif="elifForPythonProgrammers">...</h1>
  <h1 ng-else>...</h1>
```

It's a pretty silly example I suppose.

**Note:** in the above example, contrary to what you might expect coming from a sequential
programming language, <code>someOther && condition</code> is evaluated each digest *even if*
<code>someCondition</code> is <code>true</code>.  Each test expression is evaluated once per
digest *regardless* of the expressions' values.

## Testing

To build a release and run tests:

```sh
  $ npm install
  $ bower install
  $ gulp test
```

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