I try in the code like this:

<td>{{item.active | filter:getStatus(item.active) }}</td> 

Js:

 $scope.getStatus = function (item) { switch (item) { case "true": item = "Открыт"; break; case "false": item = "Закрыт"; break; case "wait": item = "Ожидает ответа"; break; case "ok": item = "Отвечен"; break; } return function (item) { return item; }; } 

As a result, I get in the output item.active: ["t","r","u","e"] What is the reason? I want item case to be substituted

    2 answers 2

    In this case, the standard filter is used , which filters the transferred array.

    What happens in your code:

    You have a function that returns a function.

     $scope.getStatus = function (item) { ... return function (item) { return item; }; } 

    And the returned function does not depend on the code that came before it. It is quite simple - it returns the argument passed.

    When the getStatus function is getStatus in the view, it returns the function that is used as a predicate for the standard filter , if this function returns truthly value - then the element remains, if falsey - then not.

    Thus, the standard filter follows the characters of the string "true", as in an array, and each character passes to the predicate function.
    This function returns this character back, filter brings the character to a boolean value and, since any character matches true , it leaves it.

    Thus, after the end of the work filter there is an array with string characters.

    What can be done: use the function directly, as in the next answer, or write your own filter, for example

     angular.module('app')// ваш модуль .filter('getStatus',function(){ return function(item){ switch (item) { case "true": return "Открыт"; case "false":return "Закрыт"; case "wait":return "Ожидает ответа"; case "ok":return "Отвечен"; } } }); 

    And use

     {{item.active | getStatus }} 

    Or even remove the function and use the object, for example

     $scope.statuses = { "true": "Открыт", "false":"Закрыт", "wait":"Ожидает ответа", "ok":"Отвечен" } 

    and use as

     {{ statuses[item.active] }} 

      You do not have a filter but a normal function. So use it as a function.

       <td>{{getStatus(item.active)}}</td> $scope.getStatus = function (item) { switch (item) { case "true": return "Открыт"; case "false": return "Закрыт"; case "wait": return "Ожидает ответа"; case "ok": return "Отвечен"; } } 

      Something like this should be.