Sanzensekai Sanzensekai - 1 year ago 87
Javascript Question

How can use a filter in my AngularJS precisely on an ng-bind?

I tried to use this simple filter :

App.filter('MyCutFilter', function ()
return function(input)
return input.replace(/^.*[\\\/]/, '');

On a element of ng-repeat like this :

<tr ng-repeat="jf in ctrl.Files" class="tablerow">
<td><span ng-bind=""></span></td>
<td><span class="filename" ng-bind="jf.FileName | MyCutFilter"></span></td>

But i got the following error :

Error: [$injector:unpr] Unknown provider: CutFilterProvider <- CutFilter <- UpFileController

What can i do to correct it ?

Thanks for your help in adavance.

Answer Source

finally i created my own service like this :

'use strict';

App.factory('UtilsService', [function(nameTable){

    return {
               parseTheseNames: function ParseThesesNames(nameTable){
                    for (var i=0; i < nameTable.length; i++)
                        nameTable[i].upFileName = nameTable[i].upFileName.replace(/^.*[\\\/]/, '');
                        //console.log("obj " + d[i].upFileName);


And i am using it like this :

App.controller('FileController',[..., 'UtilsService',...,
function(..., UtilsService, ...){

    self.upFiles = d;

I changed what i wanted to get the return of the data directly from a callback to be able to parse the filename earlier.

Thanks for the help and the documentation.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download