angularjs:$filter在尝试获取过滤数据时未定义

前端之家收集整理的这篇文章主要介绍了angularjs:$filter在尝试获取过滤数据时未定义前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
因为天试图得到这个运行:使用以下代码段我想过滤一些人,并在onchange被触发后接收已过滤的对象。看这个代码住在这里: http://jsbin.com/isojof/1/

任何想法?

还有noch $ filter Object …但是如何创建一个呢? $ filter(‘filter’)显然不工作!

<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","location":"Hamburg"},{"firstname": "Tom","age": 25,"location":"New York"},{"firstname": "Caren","lastname": "Tilt","location":"Paris"},"lastname": "Orail","age": 30,];
$scope.getData = function (names,query) {
  $scope.queryData = $filter('filter')(names,query);
  console.log($scope.queryData);
};



    }
    </script>

</body>
</html>
你只需要注入$ filter到你的控制器:

更改

function List($scope) {

function List($scope,$filter) {

http://jsbin.com/isojof/2/

猜你在找的Angularjs相关文章