angular JS中我的JavaScript中未定义过滤器
我有一个问题,我在javascript代码及其工作中使用了过滤器,但在控制台中错误地显示了这个问题。 我将此代码用于html:angular JS中我的JavaScript中未定义过滤器,javascript,angularjs,Javascript,Angularjs,我有一个问题,我在javascript代码及其工作中使用了过滤器,但在控制台中错误地显示了这个问题。 我将此代码用于html: <input type="range" min="0" max="100" step="1" ng-model="ctrl.inputAge" /> 100</p> <span>current min age: {{ ctrl.inputAge }}</span> <u
<input type="range" min="0" max="100" step="1" ng-model="ctrl.inputAge" />
100</p>
<span>current min age: {{ ctrl.inputAge }}</span>
<ul>
<li ng-repeat="person in ctrl.people | ageFilter:ctrl.inputAge ">{{ person.name }} ({{ person.age }})</li>
因此,我在控制台中发现此错误:
TypeError: Cannot read property 'filter' of undefined
您是否将过滤器
附加到现有模块?使用.filter
定义的筛选器(也在使用.controller
、.factory
、.service
等时)必须存在于模块定义的范围内。下面有一个工作示例
var-app=angular.module(“app”,[]);
应用程序控制器(“ctrl”,函数($scope){
$scope.myPersons=[{
姓名:“乔”,
年龄:30
}, {
姓名:“玛丽”,
年龄:36
}, {
姓名:“乔治”,
年龄:45
}];
});
app.filter('ageFilter',function(){
返回函数(项目、阈值){
返回items.filter(i=>i.age>threshold);
}
});代码>
{{testString}}
{{x.name}}-{x.age}
此代码不足以理解问题。请发布完整代码。很抱歉,您现在可以检查错误
TypeError: Cannot read property 'filter' of undefined