Giter VIP home page Giter VIP logo

ng-elif's Introduction

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:

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

Check out a live demo.

Dependencies

  1. AngularJS.

Installation

  • Load elif.js.

  • Add elif as a dependency to your angular module.

  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

  <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>

Testing

To build a release and run tests:

  $ npm install
  $ bower install
  $ gulp test

ng-elif's People

Contributors

zachsnow avatar jonathangawrych avatar lpappone avatar loganbarnett avatar todiadiyatmo avatar

Watchers

Thanasis Katsadas avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.