Angular JS 过滤器等于 [英] Angular JS filter equals

查看:54
本文介绍了Angular JS 过滤器等于的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请查看详细信息.为什么输出错误?

HTML:

<div ng-controller="TodoCtrl"><h1>列表</h1><div ng-repeat="t in todos | filter:{ id: '-1'}">{{t.text}}</div>

角度代码:

function TodoCtrl($scope) {$scope.todos = [{文本:'学习角度',完成:真实,编号:-1},{文本:'学习角度 2',完成:真实,编号:-11}, {text: '构建一个有角度的应用',完成:假,编号:1}];}

输出:

学习angular学习角度 2

请看:

<块引用>

过滤器:{ id:'-1'}

为什么输出包括:

学习 angular 2

我想搜索id -1,但是learn angular 2-11

解决方案

去掉 '-1' 的引号并将 true 发送到过滤器进行严格比较.

<块引用>

ng-repeat="t in todos | filter:{ id: -1}:true"

Please see the details. Why is the output wrong?

HTML:

<div ng-app>
    <div ng-controller="TodoCtrl">
         <h1>List</h1>

        <div ng-repeat="t in todos | filter:{ id: '-1'}">{{t.text}}</div>
    </div>
</div>

Angular code:

function TodoCtrl($scope) {
    $scope.todos = [{
        text: 'learn angular',
        done: true,
        id: -1
    },{
        text: 'learn angular 2',
        done: true,
        id: -11
    }, {
        text: 'build an angular app',
        done: false,
        id: 1
    }];
}

Output:

learn angular
learn angular 2

Please see:

filter:{ id: '-1'}

Why does the output include:

learn angular 2

I want to search the id -1, but learn angular 2 is -11

解决方案

Remove the quotes from '-1' and send true to the filter to do a strict comparison.

ng-repeat="t in todos | filter:{ id: -1}:true"

这篇关于Angular JS 过滤器等于的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆