过滤控制器

时间:2015-12-03 21:14:31

标签: angularjs module controller

嗨我真的需要将滤镜集成到我的控制器中,但很难, 我提供了我的控制器和我前几天制作的过滤器。 提前谢谢!

 angular.module('tickets').controller('TicketsController', ['$scope',   '$filter', '$routeParams', '$interval', '$location', 'Authentication',  'Tickets',
function($scope, $filter , $routeParams, $interval, $location, Authentication, Tickets){ contenido del controlador}]);

过滤器如下:

 .filter("filtroDate", function($filter) 
{
   return function(input)
 {
    //replace(/([^\"]*)(\d*)([^\w]*)/, replacer);
        $scope.diaActual = $filter('date')(new Date(), 'yyyy-MM-dd');
        var salida = [];
        angular.forEach($scope.tickets, function(eachtime){


        var creado = $scope.tickets.creado =  pais.diaAnt.replace(/^\"  (.*)\"/,"$1");

        console.log("Creado :",$scope.tickets.creado);

        var diaTickete = $filter('date')(new Date(creado), 'yyyy-MM-dd');

        console.log("diaTickete :", diaTickete);


         if ($scope.diaActual === diaTickete ) {   

            salida.push($scope.tickets)
          }
        })
        return salida;
    }
});

1 个答案:

答案 0 :(得分:0)

要将过滤器集成到控制器中非常简单,您只需要注入$filter服务并获取给定过滤器的实例...

app.controller('MyCtrl', function($filter){
    var myFilter = $filter('filtroDate'); //this returns the filter function!
    var result = myFilter('some-input');
})