Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
<meta name="description" content="Example of delayed filter initialization using promise in angular" />
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.24/angular.js"></script>
  <meta charset="utf-8">
  <title>Delayed Filter</title>
</head>
<body ng-app="filterExample">
  <h2>Promise in Angular Filter</h2>
  <p>{{ 'a string' | aFilter }}</p>
  <p>The above filter changes after 1 second using $timeout service.</p>
  <p>Part of the blog post at <a href="http://bahmutov.calepin.co/">http://bahmutov.calepin.co/</a></p>
</body>
</html>
 
angular.module('filterExample', [])
      .filter('aFilter', function registerAFilter($timeout) {
          var filterFn = function initialFilter(str) {
            return str + ' filtered initially';
          };
          $timeout(function () {
            filterFn = function newFilter(str) {
              return str + ' filtered with delayed!!!';
            };
          }, 1000);
          return function tempFilter(str) {
            return filterFn(str);
          };
        });
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
bahmutovpro
0viewers