Giter Club home page Giter Club logo

angular1-async-filter's Introduction

Angular1 async filter

Angular2 async pipe implemented as Angular 1 filter to handle Promises & RxJS Observables

The async filter takes a Promise or Observable as input and subscribes to the input automatically, eventually returning the emitted value(s) similarly as with Angular2 Async pipe. Works with RxJS Observables even without https://github.com/Reactive-Extensions/rx.angular.js

Install

Install from npm:

npm install angular1-async-filter --save

And bundle with Browserify, Webpack etc.

Or install with bower:

bower install angular1-async-filter --save

And add script to html:

<script src="bower_components/angular1-async-filter/async-filter.js"></script>

Add Angular module dependency. For example:

angular.module('myApp', ['asyncFilter']);

Usage

Basic usage:

<div>Value: {{ promiseOrObservable | async }}</div>

Works with any directive that takes an expression, like ng-if, ng-show and ng-repeat etc.

<ul>
    <li ng-repeat="item in list|async">{{ item }}</li>
</ul>

Angular $q and $http promises automatically trigger digest cycle when they resolve so all views will get updated. For compatibility with RxJS Observables, as well as other Promise or Observable implementations, you can provide the current scope as a parameter to the filter, which will then automatically trigger digest cycle whenever a new value is emitted:

<div ng-if="{{ observable | async:this }}">
    Value: {{ observable | async:this }}
</div>

If you are using the safeApply operator from https://github.com/Reactive-Extensions/rx.angular.js for example, then this is not needed.

Live example: http://jsbin.com/qoxaqo/edit?html,js,output

License

MIT

angular1-async-filter's People

Contributors

cvuorinen avatar sirbarrence avatar vfeskov avatar

Watchers

James Cloos avatar Daniele Morosinotto 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.