加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

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

发布时间:2020-12-17 08:30:30 所属栏目:安全 来源:网络整理
导读:因为天试图得到这个运行:使用以下代码段我想过滤一些人,并在onchange被触发后接收已过滤的对象。看这个代码住在这里: http://jsbin.com/isojof/1/ 任何想法? 还有noch $ filter Object …但是如何创建一个呢? $ filter(‘filter’)显然不工作! html ng
因为天试图得到这个运行:使用以下代码段我想过滤一些人,并在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/

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读