Sunday 15 April 2012

angularjs - My filter does not work -



angularjs - My filter does not work -

im trying alter status value numbers 'text'

i wonder how can solve it, , did wrong? give thanks in advance

<table> <tr ng-repeat="x in id"> <td>{{ x.id }}</td> <td>{{ x.status | status}}</td> </tr> </table>

when write | status <- crashes whole ng repeat , nil displays.

var app = angular.module('customerscontroller', []); function customerscontroller($scope, $http) { $http.get("localhost") .success(function (response) { $scope.id = response; }); app.filter('status', function () { homecoming function (input) { var statu; switch (input) { case 10: statu = 'bronze'; break; case 20: statu = 'silver'; break; case 30: statu = 'gold'; break; case 40: statu = 'elite'; break; } homecoming statu; }; });

you're defining filter within controller. not valid. may add together filters module during configuration phase, before app started , controller instantiated. code should be:

var app = angular.module('customerscontroller', []); app.filter('status', function () { homecoming function (input) { var statu; switch (input) { case 10: statu = 'bronze'; break; case 20: statu = 'silver'; break; case 30: statu = 'gold'; break; case 40: statu = 'elite'; break; } homecoming statu; }; }); app.controller('customerscontroller', function($scope, $http) { $http.get("localhost") .success(function (response) { $scope.id = response; }); });

angularjs angularjs-filter

No comments:

Post a Comment