Html 角网格中的动态分页

Html 角网格中的动态分页,html,angularjs,pagination,angular-ui-bootstrap,angular-bootstrap,Html,Angularjs,Pagination,Angular Ui Bootstrap,Angular Bootstrap,我构建了一个angular应用程序,其中包含数据表。我使用分页概念来显示它,页面中有3行,它可以工作,但是当我向表中添加新数据(用户)时,它不会在分页栏中添加页面 角度代码: app = angular.module('ui.bootstrap.demo', ['ngAnimate', 'ui.bootstrap']); app.controller('AppCtrl', function($scope, $modal, $log ) { $scope.Users = [{

我构建了一个angular应用程序,其中包含数据表。我使用分页概念来显示它,页面中有3行,它可以工作,但是当我向表中添加新数据(用户)时,它不会在分页栏中添加页面

角度代码:

app = angular.module('ui.bootstrap.demo', ['ngAnimate', 'ui.bootstrap']);
app.controller('AppCtrl', function($scope, $modal, $log ) {
    $scope.Users = [{
        'userN': 'Ariel1',
        'PassW': 'Aa123456',
        'Name': 'Ariel',
        'LastName': 'Livshits'
    }, {
        'userN': 'Ariel2',
        'PassW': 'Aa123456',
        'Name': 'Ariel',
        'LastName': 'Livshits'
    }, {
        'userN': 'Ariel3',
        'PassW': 'Aa123456',
        'Name': 'Ariel',
        'LastName': 'Livshits'
    }, {
        'userN': 'Ariel4',
        'PassW': 'Aa123456',
        'Name': 'Ariel',
        'LastName': 'Livshits'
    }, {
        'userN': 'Ariel5',
        'PassW': 'Aa123456',
        'Name': 'Ariel',
        'LastName': 'Livshits'
    }, {
        'userN': 'Ariel6',
        'PassW': 'Aa123456',
        'Name': 'Ariel',
        'LastName': 'Livshits'
    }, {
        'userN': 'Ariel6',
        'PassW': 'Aa123456',
        'Name': 'Ariel',
        'LastName': 'Livshits'
    }, {
        'userN': 'Ariel6',
        'PassW': 'Aa123456',
        'Name': 'Ariel',
        'LastName': 'Livshits'
    }];

    $scope.User = {
        'username': '',
        'Password': '',
        'connected': false
    };


    $scope.viewby = 3;
    $scope.totalItems = $scope.Users.length;
    $scope.currentPage = 1;
    $scope.itemsPerPage = $scope.viewby;
    $scope.maxSize = ($scope.Users.length / 3) + 1; //Number of pager buttons to show

    $scope.setPage = function (pageNo) {
        $scope.currentPage = pageNo;
    };

    $scope.pageChanged = function() {
        console.log('Page changed to: ' + $scope.currentPage);
    };

    $scope.setItemsPerPage = function(num) {
        $scope.itemsPerPage = num;
        $scope.currentPage = 1; //reset to first paghe
    };


    $scope.openR = function() {

        var modalInstance = $modal.open({
            templateUrl: 'table.html',
            controller: 'ModalInstanceCtrl'
        });
        modalInstance.result.then(function(newUser) {
            $scope.Users.push(newUser);
        }, function() {
            $log.info('Modal dismissed at: ' + new Date());
        });
    };
    $scope.openC = function() {

        var modalInstance = $modal.open({
            templateUrl: 'connect.html',
            controller: 'ModalInstanceCtrl'
        });
        modalInstance.result.then(function(conUser) {
            $scope.User = conUser;
        }, function() {
            $log.info('Modal dismissed at: ' + new Date());
        });
    };
});

// Please note that $modalInstance represents a modal window (instance) dependency.
// It is not the same as the $modal service used above.

app.controller('ModalInstanceCtrl', function($scope, $modalInstance) {
    $scope.okR = function() {
        $modalInstance.close({
            'userN': $scope.userN,
            'PassW': $scope.PassW,
            'Name': $scope.Name,
            'LastName': $scope.LastName
        });
    };

    $scope.okC = function() {
        $modalInstance.close({
            'username': $scope.username,
            'Password': $scope.password,
            'connected': true
        });
    };

    $scope.cancel = function() {
        $modalInstance.dismiss('cancel');
    };
});
html代码:

<!doctype html>
<html ng-app="ui.bootstrap.demo">

<head>
    <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.4.3/angular.js"></script>
    <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.4.3/angular-animate.js"></script>
    <script src="//angular-ui.github.io/bootstrap/ui-bootstrap-tpls-0.13.3.js"></script>
    <script src="app.js"></script>
    <link href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet">
</head>

<body>

<div ng-controller="AppCtrl" >
    <button type="button" class="btn btn-default" ng-click="openR()"> add user </button>
    <button type="button" class="btn btn-default" ng-click="openC()"> connect </button>
    <div class="btn btn-success" ng-show="User.connected">{{User.username}} is connected</div>
    <table>
        <thead>
        <th class="col-lg-3">Username</th>
        <th class="col-lg-3">Password</th>
        <th class="col-lg-3">First name</th>
        <th class="col-lg-3">Last name</th>
        </thead>
        <tbody>
        <tr ng-repeat="User in Users.slice(((currentPage-1)*itemsPerPage), ((currentPage)*itemsPerPage))">
            <td class="col-lg-3">{{User.userN}}</td>
            <td class="col-lg-3">{{User.PassW}}</td>
            <td class="col-lg-3">{{User.Name}}</td>
            <td class="col-lg-3">{{User.LastName}}</td>
        </tr>
        </tbody>
    </table>
    <div >
        <pagination total-items="totalItems" ng-model="currentPage" ng-change="pageChanged()" class="pagination-sm" items-per-page="itemsPerPage"></pagination>
    </div>
</div>
<script type="text/ng-template" id="table.html">
    <form ng-submit="okR()">
        <div class="modal-header" >
            <h3>users</h3>
        </div>
        <div class="modal-body">
            <div class="panel-body">
                <div class="form-group">
                    <label>Username :</label>
                    <input type="text" placeholder="Ariel73" ng-model="userN">
                </div>
                <div class="form-group">
                    <label>Password :</label>
                    <input type="text" placeholder="Aa123456" ng-model="PassW">
                </div>
                <div class="form-group">
                    <label>First name :</label>
                    <input type="text" placeholder="Ariel" ng-model="Name">
                </div>
                <div class="form-group">
                    <label>Last name :</label>
                    <input type="text" placeholder="Livshits" ng-model="LastName">
                </div>
            </div>
            <div class="modal-footer">
                <button type="submit"  class="btn btn-success">Submit</button>
            </div>
        </div>
    </form>
</script>
<script type="text/ng-template" id="connect.html">
    <form ng-submit="okC()">
        <div class="modal-header" >
            <h3>users</h3>
        </div>
        <div class="modal-body">
            <div class="panel-body">
                <div class="form-group">
                    <label>Username :</label>
                    <input type="text" placeholder="Ariel73" ng-model="username">
                </div>
                <div class="form-group">
                    <label>Password :</label>
                    <input type="text" placeholder="Aa123456" ng-model="password">
                </div>
            </div>
            <div class="modal-footer">
                <button type="submit"  class="btn btn-success">Submit</button>
            </div>
        </div>
    </form>
</script>
</body>

</html>

添加用户
连接
{{User.username}}已连接
用户名
密码
名字
姓
{{User.userN}
{{User.PassW}
{{User.Name}
{{User.LastName}
使用者
用户名:
密码:
名字:
姓氏:
提交
使用者
用户名:
密码:
提交
分页是您自己的指令吗

angular的工作方式是,当指令加载时,它只运行一次“控制器”代码

你可以做两件事中的一件。在“分页”控制器中添加一个“监视”,以便在指令分页上的一个“范围变量”更新时进行更新。或者设置一个事件(广播或发射,以及打开),让分页知道在用户更新时更新

下面是设置$watch变量的详细文档

“分页”是您自己的指令吗

angular的工作方式是,当指令加载时,它只运行一次“控制器”代码

你可以做两件事中的一件。在“分页”控制器中添加一个“监视”,以便在指令分页上的一个“范围变量”更新时进行更新。或者设置一个事件(广播或发射,以及打开),让分页知道在用户更新时更新


下面是设置$watch变量的详细文档

请参阅分页我的分页正在工作。问题是,当我将用户添加到表中时,它不会在分页栏中添加新页面。此链接没有解决方案。有关分页,请参阅我的分页正在工作。问题是,当我将用户添加到表中时,它不会在分页栏中添加新页面。此链接没有解决此问题的方法。