将内容预先添加到ng-repeat

时间:2018-01-05 14:35:42

标签: angularjs angularjs-ng-repeat angularjs-orderby angularjs-limitto

我有一个ng-repeat指令从静态json文件中提取数据。我使用过滤器来限制指令和按钮的项目数量来增加/减少该限制。我希望在单击按钮时将内容添加到列表中(添加到顶部)。 请注意,我不需要增加de数组,我已经在json上加载了我需要的所有数据。



<!DOCTYPE html>
<html lang="pt-BR" ng-app="myApp">
<head>
    <script src="js/angular.min.js"></script>
    <script src="js/angular-sanitize.min.js"></script>
    <script>
        var myApp = angular.module('myApp', ['ngSanitize']);
        myApp.controller('myController', function myController($scope,$http){
            $http.get('js/exemple.json').then(function(response){
                $scope.exemple = response.data;
            });
        })
    </script>
</head>
<body class="home" ng-controller="myController">
    <form class="filtro">
        <label>
            Filtrar por: <strong>{{query}}</strong> <br> <input type="text" placeholder="Digite para filtrar" ng-model="query"> 
        </label>
        <label>
            <input type="radio" ng-model="filtrarPor" name="filtro" value="" checked class="checked"> padrão 
        </label>
        <label>
            <input type="radio" ng-model="filtrarPor" name="filtro" value="cliente"> cliente 
        </label>
        <label>
            <input type="radio" ng-model="filtrarPor" name="filtro" value="tipo"> tipo
        </label>
        <button ng-click="limit = limit + 3" ng-disabled="limit >= exemple.portifolio.length">mostrar mais</button>
        <button ng-click="limit = limit - 3" ng-disabled="limit == 3">mostrar menos</button>
    </form>
    <div class="portifolio-itens" ng-init="limit = 6">
        <div class="portifolio-item" ng-repeat="item in exemple.portifolio | filter:query | orderBy:filtrarPor | limitTo:limit">
            <a data-id="#job{{$index}}">
                <h3>{{item.tipo}}</h3>
                <h4>{{item.cliente}}</h4>
                <p>{{item.info}}</p>
            </a>
        </div>
    </div>
</body>
</html>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

感谢您的评论!我设法通过CSS flexbox实现了我所需要的,而没有改变我发布的js / html的任何方面:

&#13;
&#13;
.portifolio-itens {display: flex; flex-wrap: wrap-reverse;}
&#13;
&#13;
&#13;