1

I am new to Angular JS and working with custom filter for Month in Date of Birth option.

The function monthName has been defined inside the controller.

When i try to run the file an error :-

Uncaught ReferenceError: monthName is not defined

HTML :-

<select ng-model="main.userdobmonth" ng-change="main.getMonthDays()">
    <option ng-selected="{{$index+1==main.userdobmonth}}" value="{{$index+1}}" 
            ng-repeat="a in main.rangeDate(12) track by $index">{{$index+1 | monthName}}</option>
</select>

My controller code :-

angular.module('HC', ['ngAnimate'])
    .controller('MainController', MainController)
    .filter('monthName', monthName);

// Inject dependencies
MainController.$inject = ['U', 'M', 'S', '$filter', '$upload', '$timeout'];

function MainController(U, M, S, $filter, $upload, $scope, $timeout) {

    // ....

    function monthName() {
        return function (monthNumber) { //1 = January
            var monthNames = ['January', 'February', 'March', 'April', 'May', 'June',
                'July', 'August', 'September', 'October', 'November', 'December'];
            return monthNames[monthNumber - 1];
        }
    }

}

Any solution ?

1 Answer 1

3

You defined monthName inside of MainController. As the result it's a local variable which is not accessible outside where you try to use it. Solution is to move it outside.

function MainController (U, M, S, $filter, $upload, $scope, $timeout) { ... }

function monthName () { ... }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.