博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
如何使用多个参数调用Angular.js过滤器?
阅读量:2288 次
发布时间:2019-05-09

本文共 2543 字,大约阅读时间需要 8 分钟。

本文翻译自:

As from the , we can call a filter such as like this: 从中我们可以调用像这样的过滤器:

{
{ myDateInScope | date: 'yyyy-MM-dd' }}

Here date is a filter that takes one argument. 这里date是一个带有一个参数的过滤器。

What is the syntax to call filters with more parameters both from templates and from JavaScript code? 从模板和JavaScript代码调用带有更多参数的过滤器的语法是什么?


#1楼

参考:


#2楼

In templates, you can separate filter arguments by colons . 在模板中,您可以使用冒号分隔过滤器参数。

{
{ yourExpression | yourFilter: arg1:arg2:... }}

From Javascript, you call it as 从Javascript,你称之为

$filter('yourFilter')(yourExpression, arg1, arg2, ...)

There is actually an example hidden in the filter docs. 实际上, 过滤器文档中隐藏了一个示例。


Example: 例:

Let's say you make a filter that can replace things with regular expressions: 假设您创建了一个可以用正则表达式替换事物的过滤器:

myApp.filter("regexReplace", function() { // register new filter  return function(input, searchRegex, replaceRegex) { // filter arguments    return input.replace(RegExp(searchRegex), replaceRegex); // implementation  };});

Invocation in a template to censor out all digits: 在模板中调用以检查所有数字:

{

{ myText | regexReplace: '[0-9]':'X' }}


#3楼

i mentioned in the below where i have mentioned the custom filter also , how to call these filter which is having two parameters 我在下面提到过我自己也提到了自定义过滤器,如何调用这些有两个参数的过滤器

countryApp.filter('reverse', function() {    return function(input, uppercase) {        var out = '';        for (var i = 0; i < input.length; i++) {            out = input.charAt(i) + out;        }        if (uppercase) {            out = out.toUpperCase();        }        return out;    }});

and from the html using the template we can call that filter like below 从使用模板的html我们可以像下面那样调用该过滤器

{
{inputString| reverse:true }}

here if you see , the first parameter is inputString and second parameter is true which is combined with "reverse' using the : symbol 在这里,如果你看到,第一个参数是inputString,第二个参数是true,它与使用:符号的“反向”组合


#4楼

If you want to call your filter inside ng-options the code will be as follows: 如果要在ng-options中调用过滤器,代码如下:

ng-options="productSize as ( productSize | sizeWithPrice: product )  for productSize in productSizes track by productSize.id"

where the filter is sizeWithPriceFilter and it has two parameters product and productSize 过滤器的大小是sizeWithPriceFilter,它有两个参数product和productSize


#5楼

If you need two or more dealings with the filter, is possible to chain them: 如果您需要与过滤器进行两次或更多次交易,可以将它们链接起来:

{
{ value | decimalRound: 2 | currencySimbol: 'U$' }} // 11.1111 becomes U$ 11.11

#6楼

像这样:

var items = $filter('filter')(array, {Column1:false,Column2:'Pending'});

转载地址:http://gwjnb.baihongyu.com/

你可能感兴趣的文章
Dockerfile创建镜像
查看>>
Docker镜像仓库搭建 图形化Harbor
查看>>
Kubernetes集群组件安装(二进制安装)
查看>>
阿里云ECS磁盘在线扩容后扩容磁盘
查看>>
K8S控制器Deployment
查看>>
Ambari安装
查看>>
使用ambari创建Hadoop集群
查看>>
KVM和Qemu的区别
查看>>
KVM
查看>>
NoSQL分类
查看>>
MongoDB安装
查看>>
MongoDB基础操作
查看>>
MongoDB用户权限管理
查看>>
Zabbix 安装配置
查看>>
zabbix自定义监控项
查看>>
zabbix报警功能(邮件报警)---触发器/动作
查看>>
zabbix微信报警
查看>>
微信报警脚本
查看>>
Gitlab源
查看>>
MySQL二进制安装5.7.26
查看>>