Javascript 自定义过滤器未定义
我是Angular JS的新手,使用出生日期选项中月份的自定义过滤器 功能monthName已在控制器内定义 当我尝试运行该文件时,出现一个错误:-Javascript 自定义过滤器未定义,javascript,angularjs,Javascript,Angularjs,我是Angular JS的新手,使用出生日期选项中月份的自定义过滤器 功能monthName已在控制器内定义 当我尝试运行该文件时,出现一个错误:- Uncaught ReferenceError: monthName is not defined HTML:- <select ng-model="main.userdobmonth" ng-change="main.getMonthDays()"> <option ng-selected="{{$index+1==m
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>
有解决方案吗?您在
MainController
内部定义了monthName
。因此,它是一个局部变量,在尝试使用它的外部无法访问。解决办法是把它移到外面
function MainController (U, M, S, $filter, $upload, $scope, $timeout) { ... }
function monthName () { ... }
function MainController (U, M, S, $filter, $upload, $scope, $timeout) { ... }
function monthName () { ... }