Tutorial 10.3 Stateful Filters

******************************************INDEX.HTML*****************************************************
<!doctype html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Example - example-filter-stateful-production</title>
 

  <script src="//code.angularjs.org/snapshot/angular.min.js"></script>
  <script src="script.js"></script>
 

 
</head>
<body ng-app="myStatefulFilterApp">
  <div ng-controller="MyController">
  Input: <input ng-model="greeting" type="text"><br>
  Decoration: <input ng-model="decoration.symbol" type="text"><br>
  No filter: {{greeting}}<br>
  Decorated: {{greeting | decorate}}<br>
</div>
</body>
</html>
******************************************INDEX.HTML*****************************************************
********************************************script.js***************************************************
(function(angular) {
  'use strict';
angular.module('myStatefulFilterApp', [])
  .filter('decorate', ['decoration', function(decoration) {

    function decorateFilter(input) {
      return decoration.symbol + input + decoration.symbol;
    }
    decorateFilter.$stateful = true;

    return decorateFilter;
  }])
  .controller('MyController', ['$scope', 'decoration', function($scope, decoration) {
    $scope.greeting = 'hello';
    $scope.decoration = decoration;
  }])
  .value('decoration', {symbol: '*'});
})(window.angular);
********************************************script.js***************************************************

Comments

Popular posts from this blog

Tutorial 12.12 Creating a Directive that Wraps Other Elements 3

Tutorial 12.14 Creating Directives that Communicate