角JS - 显示消息如果异常重复是空的 [英] Angular js - Show message if ng-repeat is empty

查看:96
本文介绍了角JS - 显示消息如果异常重复是空的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下AngularJS应用程序正在与NG-重复和应用的过滤器。某应用过滤器没有留下left值。我怎样才能显示通知?

爵士小提琴

HTML

 < D​​IV>
< D​​IV数据-NG-控制器=myCtrl>
    < UL>
        <李数据-NG-重复=项的值|过滤器:filterIds()>
            < code>#{{item.id}}< / code>项目
        < /李>
    < / UL>    < p NG秀=values​​.length!>在此滤波器LT无丘壑; / P>
    <按钮NG点击=loadNewFilter()>现在&LT过滤; /按钮>
< / DIV>
< / DIV>

AngularJS

  VAR应用= angular.module('M',[]);app.controller('myCtrl',函数($范围){
$ scope.values​​ = [{
    ID:1
} ....
}];$ scope.filter = [1,2,3,4,5,6]$ scope.filterIds =功能(IDS){
        复位功能(项目){
            VAR过滤器= $ scope.filter;                 返回filter.indexOf(item.id)== -1!;
        }
 }$ scope.loadNewFilter =功能(){
    $ scope.filter = [-1];
    $ $范围适用于()。
}});


解决方案

我认为这是你想要什么:

 < D​​IV>
    < D​​IV数据-NG-控制器=myCtrl>
        < UL>
            <李数据-NG-重复=在testValue项=(值|过滤器:filterIds())>
                < code>#{{item.id}}< / code>项目
            < /李>
        < / UL>        < p NG秀=testValue.length!>在此滤波器LT无丘壑; / P>
        <按钮NG点击=loadNewFilter()>现在&LT过滤; /按钮>
    < / DIV>

过滤后,结果存储在 testValue 。所以每当你更换过滤器,testValue'也改变了。

  VAR应用= angular.module('M',[]);app.controller('myCtrl',函数($范围){
    $ scope.values​​ = [{
        ID:1
    },{
        ID:2
    },{
        ID:3
    },{
        ID:4
    },{
        ID:5
    },{
        ID:6
    }];    $ scope.filter = [1,2,3,4,5,6]    $ scope.filterIds =功能(IDS){
            复位功能(项目){
                VAR过滤器= $ scope.filter;                     返回filter.indexOf(item.id)== -1!;
            }
     }    $ scope.loadNewFilter =功能(){
        $ scope.filter = [1,5];
        $ $范围适用于()。
    }});

FIDDLE LINK

这是另外一个FIDDLE菱格纹这也是

The following AngularJS application is working with ng-repeat and an applied filter. A certain applied filter leaves no values left. How can I display a notification?

js fiddle

HTML

<div >
<div data-ng-controller="myCtrl">


    <ul >
        <li data-ng-repeat="item in values | filter:filterIds()"> 
            <code>#{{item.id}}</code> Item
        </li>
    </ul>

    <p ng-show="!values.length">no vals with this filter</p>
    <button ng-click="loadNewFilter()"> filter now</button>
</div>


</div>

AngularJS

var app = angular.module('m', []);

app.controller('myCtrl', function ($scope) {
$scope.values = [{
    id: 1
}, ....
}];

$scope.filter = [1,2,3,4,5,6];

$scope.filterIds = function (ids) {
        return function (item) {
            var filter = $scope.filter;

                 return filter.indexOf(item.id) !== -1;         
        }
 }

$scope.loadNewFilter = function (){
    $scope.filter = [-1];
    $scope.$apply();
}

});

解决方案

I think that this is what you want:

<div >
    <div data-ng-controller="myCtrl">


        <ul >
            <li data-ng-repeat="item in testValue=(values | filter:filterIds())"> 
                <code>#{{item.id}}</code> Item
            </li>
        </ul>

        <p ng-show="!testValue.length">no vals with this filter</p>
        <button ng-click="loadNewFilter()"> filter now</button>
    </div>

After filtering values, the results are stored in testValue. So whenever you change the filter, 'testValue' also changes.

var app = angular.module('m', []);

app.controller('myCtrl', function ($scope) {
    $scope.values = [{
        id: 1
    }, {
        id: 2
    }, {
        id: 3
    }, {
        id: 4
    }, {
        id: 5
    }, {
        id: 6
    }];

    $scope.filter = [1,2,3,4,5,6];

    $scope.filterIds = function (ids) {
            return function (item) {
                var filter = $scope.filter;

                     return filter.indexOf(item.id) !== -1;         
            }
     }

    $scope.loadNewFilter = function (){
        $scope.filter = [1,5];
        $scope.$apply();
    }



});

FIDDLE LINK

This is Another one FIDDLE LINK check this also

这篇关于角JS - 显示消息如果异常重复是空的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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