wachme / angular-defer

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

angular-defer

Simple utility service for invoking asynchronous functions. It allows scope to watch value returned from a asynchronous call.

Example:

var module = angular.module('example', ['Defer']);

module.factory('Data', function($http, defer) {
    return defer(function(d) {  // d is the deferred object
        $http.get('/data.json').success(function(data) {
            d.resolve(data);  // resolve deferred and automatically update returned object
        });
    });
});

module.controller('Ctrl', function($scope, Data) {
    $scope.data = Data;  // you can refer to data in template
    
    $scope.$watch('data', function() {
        console.log('data has been updated!');
    });
});

About


Languages

Language:JavaScript 95.3%Language:CSS 4.7%