Friday, 15 January 2010

AngularJS using Filter inside a Controller -



AngularJS using Filter inside a Controller -

var app = angular.module('app', ['ui.bootstrap']); app.controller('appctrl', ['$scope', '$http', function($scope, $http, ngtableparams, $filter){ $http.get('/assets/inc/data').success(function(response) { $scope.items = response; $filter('offset', function() { homecoming function(input, start) { console.log(start); start = parseint(start, 10); homecoming input.slice(start); }; }); }); }]);

i have little applications trying utilize $filter in. filter needs available when $http.get has finished running above doesn't work.

where have went wrong?

you're sort of mixing things up. filter has created app.filter() , afterwards applied sylwester mentioned.

create:

app.filter('filtername' , function() { homecoming function(arg1, arg2, ..., argn) { // ever homecoming ...; }; });

apply:

$filter('filtername') (arg1, arg2, ..., argn);

see: plunkr

angularjs angularjs-scope angularjs-filter

No comments:

Post a Comment