angularjs:试图让过滤数据时$过滤器是未定义 [英] angularjs: $filter is undefined when trying to get filtered data
本文介绍了angularjs:试图让过滤数据时$过滤器是未定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
由于天IM试图让这个运行:通过下面的代码片段,我想过滤某些人和的onchange被解雇后接受已过滤的对象。看到这个code住在这里: http://jsbin.com/isojof/1/
任何想法?
有是NOCH $滤镜对象,可是...可是怎么建立呢? $过滤器('过滤器')显然是不工作!
< HTML NG-应用>
< HEAD>
<间的charset =UTF-8>
<标题>文件< /标题>
<脚本类型=文/ JavaScript的SRC =https://ajax.googleapis.com/ajax/libs/angularjs/1.0.1/angular.min.js>< / SCRIPT>< /头>
<机身NG控制器=列表> 搜索:LT;输入NG-变化=的getData(姓名,查询)NG模型=查询>
搜索:LT;选择NG-变化=的getData(姓名,QUERY2)NG模型=QUERY2>
<选项>< /选项>
<选项>&柏林LT; /选项>
<选项>汉堡< /选项>
< /选择>
< DIV>
< UL类=名称>
<李NG模型=项,NG-重复=名称名称|过滤:查询|过滤:QUERY2>
{{name.firstname}},{{name.lastname}},{{name.age}},{{名称。位置}}
< /李>
< / UL>
< / DIV>
<脚本类型=文/ JavaScript的>
功能列表($范围){
$ scope.names = [
{名字:卡尔,
姓氏:Luyk
时代:20,
位置:柏林},
{名字:卡尔,
姓氏:莫林
时代:20,
位置:汉堡},
{名字:汤姆,
姓氏:Luyk
时代:25,
位置:纽约},
{名字:卡伦
姓氏:倾斜
时代:20,
位置:巴黎},
{名字:卡伦
姓氏:Orail
时代:30,
位置:汉堡},
];
$ scope.getData =功能(姓名,查询){
$ scope.queryData = $过滤器('过滤器')(姓名,查询);
的console.log($ scope.queryData);
}; }
< / SCRIPT>< /身体GT;
< / HTML>
解决方案
您只需要注入 $过滤器
到控制器:
修改
函数列表($范围){
到
函数列表($范围,$过滤器){
Since days im trying to get this running: With the following snippet i want to filter some persons and after onchange was fired receive the objects which have been filtered. see this Code live here: http://jsbin.com/isojof/1/
Any idea?
There is noch $filter Object yet...but how to create one? $filter('filter') is obviously not working!
<html ng-app>
<head>
<meta charset="UTF-8">
<title>Document</title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.1/angular.min.js"></script>
</head>
<body ng-controller="List">
Search: <input ng-change="getData(names, query)" ng-model="query">
Search: <select ng-change="getData(names, query2)" ng-model="query2">
<option></option>
<option>Berlin</option>
<option>Hamburg</option>
</select>
<div>
<ul class="names" >
<li ng-model="item" " ng-repeat="name in names | filter:query | filter:query2">
{{name.firstname}}, {{name.lastname}}, {{name.age}}, {{name.location}}
</li>
</ul>
</div>
<script type="text/javascript">
function List($scope) {
$scope.names = [
{"firstname": "Carl",
"lastname": "Luyk",
"age": 20,
"location":"Berlin"},
{"firstname": "Carl",
"lastname": "Moreen",
"age": 20,
"location":"Hamburg"},
{"firstname": "Tom",
"lastname": "Luyk",
"age": 25,
"location":"New York"},
{"firstname": "Caren",
"lastname": "Tilt",
"age": 20,
"location":"Paris"},
{"firstname": "Caren",
"lastname": "Orail",
"age": 30,
"location":"Hamburg"},
];
$scope.getData = function (names, query) {
$scope.queryData = $filter('filter')(names, query);
console.log($scope.queryData);
};
}
</script>
</body>
</html>
解决方案
You just need to inject $filter
into your controller:
Change
function List($scope) {
to
function List($scope, $filter) {
这篇关于angularjs:试图让过滤数据时$过滤器是未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文