gpt4 book ai didi

angularjs - 如何将参数传递给 angular js 中的过滤器函数

转载 作者:行者123 更新时间:2023-12-04 02:39:55 26 4
gpt4 key购买 nike

我有两个问题。

  • 如何将参数传递给过滤器函数。

    比如说:item in masterData|filter1:masterdata|filter2:outputFromfilter1, myparam | filter3:outputFromfilter2, myparam1,myparam2
  • 如何访问 Controller $scope在过滤器函数中。
    animateAppModule.filter( 'distinct' , function(){
    return function(masterdata){
    //HOW TO ACCESS THE $scope HERE
    }
    })

  • 这是一个 fiddle .请。查看 Firebug 控制台,看到传递给过滤器的参数是 undefined .

    最佳答案

    对于您的第一个问题:

    您可以给出由 : 分隔的参数进入过滤器。
    例如,

    {{ array | myfilter:a:b:c }}

    在您的过滤器定义中,
    angular.module('app', []).
    filter('myfilter', function() {
    return function(in, param1, param2, param3) {
    // do something
    };
    });

    对于你的第二个问题。

    不知道为什么您需要访问 $scope .
    你能简单地通过 param 提供任何需要的信息作为你的 Q1 吗?

    关于angularjs - 如何将参数传递给 angular js 中的过滤器函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14841897/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com