zoukankan      html  css  js  c++  java
  • AngularJS入门基础——过滤器

    在HTML中的模板绑定符号{{ }}内通过 | 符号来调用过滤器

    {{ name | uppercase }}
     
    以HTML的形式使用过滤器时,如果需要传递参数给过滤器,只要在过滤器名字后面加冒号即可。如果有多个参数,可以在每个参数后面都加入冒号。
     
    内置的过滤暂时就不记录笔记了,那么接下来我们自己做一个自定义的过滤器
     
    //HTML
    <div ng-controller="FilterController">
      {{ "abkjlsjdljfljsilnsldlkmflskdmflk" | breviary }}
    </div>
     
    //SCRIPT
    <script type="text/javascript">
      angular.module("myApp", [])
        .controller("FilterController", function($scope) {
          // do nothing
        })
        .filter("breviary", function() {
          return function(str) {
            if (str) {
              return str[0].toUpperCase() + str.substring(1, 10) + "...";
            }
          };
        });
    </script>
    通过分享,结交好友~ 如本文对您有益,请给予关注。转载请注明出处!-- 小数
  • 相关阅读:
    css3 box-shadow
    JS的Document属性和方法
    简单配色方案web
    ps中参考线的使用技巧
    min-width() ie6
    js 模拟右键菜单
    display:table-cell
    js opener 的使用
    js的 new image()
    CSS 中文字体 Unicode 编码方案
  • 原文地址:https://www.cnblogs.com/mcat/p/4186748.html
Copyright © 2011-2022 走看看