Ahmed
Ahmed

Reputation: 255

How to fix error with toUpperCase?

I have variable in Angular JS:

$scope.formData.time

That contains format: "12:00:00"

I have filter:

.filter('timeApp', function ($filter) {
            return function (input) {
                if (input == null) {
                    return "";
                }

                var _date = $filter('date')(new Date(input), 'HH:mm:ss');
                return _date.toUpperCase();

            }
        })

When I call this filter for $scope.formData.time:

$scope.formData.time = $filter('timeApp')($scope.formData.time);

I get error:

TypeError: _date.toUpperCase is not a function at line 

return _date.toUpperCase();

Upvotes: 0

Views: 582

Answers (2)

oded
oded

Reputation: 179

I don't know if it still relevant but I had the same problem and this what help for me:

instead of

if (input == null)

use:

if(input == null || input == "0000-00-00" || input == "0000-00-00 00:00:00"){ return ""; } 

Upvotes: 0

Zohaib Ijaz
Zohaib Ijaz

Reputation: 22925

I don't know if this line is correct or not

 var _date = $filter('date')(new Date(input), 'HH:mm:ss');

but other possible error can be that you are only cheching for `null' do something like

if (input)

instead of

if (input == null)

Upvotes: 1

Related Questions