zoukankan      html  css  js  c++  java
  • angularJS 中 filter

    自定义过滤器:

    module.filter('过滤器名称',function(){

      return function ('带过滤的数据' , '条件1' , '条件2'){

        return '带过滤的数据' ? '条件1' : '条件2'

      }

    })

    <!DOCTYPE html>
    <html ng-app="MyApp">
    <head>
        <title>Your first directive</title>
        <script src="angular.js">
        </script>
        <script type="application/javascript">
            var module = angular.
                module('MyApp', []);
        </script>
    </head>
    
    <body>
        <div ng-controller="RequestsController">
            <div ng-repeat="request in requests">
                <a ng-href="{{ request.done | conditional:'/history':'/request' }}">
                    {{ request.done | conditional:'Done':'In Progress' }}
                </a>
            </div>
        </div>
    
        <script type="text/javascript">
            function RequestsController($scope) {
                $scope.requests = [];
                for (var i = 0; i < 50; ++i) {
                    $scope.requests.push({ done : (i % 3 == 0) });
                }
            }
    
            module.filter('conditional', function() {
                return function(b, t, f) {
                    return b ? t : f;
                };
            });
        </script>
    </body>
    
    </html>
    

      

  • 相关阅读:
    06-tree Shaking
    05-babel-解析高级js语法+polyfill按需注入
    Symbol.iterator
    回调
    finally
    then的参数
    通过简单例子看Promise(一)
    作为Promise构造函数参数的函数
    resolved和rejected
    resolve和reject
  • 原文地址:https://www.cnblogs.com/dyy-dida/p/9883728.html
Copyright © 2011-2022 走看看