0

var app = angular.module('pixmall', []); app.controller('myDashboard', function($scope, $http) { app.filter('myRandom', function() { return function (input) { return Math.round(input); } });
<div ng-app="pixmall" ng-controller="myDashboard"> <span>{{30.35 | myRandom}}</span> </div>

I want to use the filter to round the number to the nearest whole number but it is not working, I don't know what is wrong

1 Answer 1

2

Separate out the controller and filter, you should not place the filter within the controller code.

DEMO

var app = angular.module('pixmall', []) app.controller("myDashboard",function($scope){ }); app.filter('myRandom', function() { return function (input) { return Math.round(input); } });
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.7/angular.min.js"></script> <div ng-app="pixmall" ng-controller="myDashboard"> <span>{{30.35 | myRandom}}</span> </div>

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.