zoukankan      html  css  js  c++  java
  • angularJS自定义 过滤器基础

    先写个简单的例子,该过滤器是指定规定的字符串长度:

    html:

    <div ng-app="app" ng-controller="ctrl">
    <p ng-repeat="text in texts>
    {{book | limitText:10}}
    </p>
    </div>

    js:

    var app = angular.module("app",[]);
    app.filter('limitText', function() {
    return function(input, num) {
    if(input.length>num){
    input = input.substring(0,num)+"...";
    }
    return input;
    };
    });
    app.controller("ctrl",["$scope",function($scope){
    $scope.texts = ["大帅哥多发个梵蒂冈梵蒂冈","法规的非官","儿童热太热一天如图于一体"];
    }]);

    显示

    大帅哥多发个梵蒂冈梵...

    法规的非官

    儿童热太热一天如图于...

    自定义过滤器可以接受参数(可多个),也可以不用参数。

    但参数必须写在return 后面函数的第二个参数里,第一个参数是要处理的对象。

    多个参数的用法

    {{ expression | filter:argument1:argument2:... }}

  • 相关阅读:
    13.sqoop的安装
    12.Flume的安装
    11.把文本文件的数据导入到Hive表中
    10.hive安装
    9.centos7 安装mysql
    8.时间同步
    7.编写mapreduce案例
    mysql中如何处理字符
    装箱拆箱隐含的问题
    何谓幂等性
  • 原文地址:https://www.cnblogs.com/Ushadow/p/5678469.html
Copyright © 2011-2022 走看看