First, create an index.html page
<!doctype html>
<html ng-app="mainApp">
<head>
<meta charset="UTF-8"/>
<title>Angular JS + Spring MVC test</title>
<link rel="stylesheet" href="resources/bootstrap/css/bootstrap.min.css" />
<script src="resources/js/lib/angular/angular.js"></script>
<script src="resources/js/lib/angular/angular-resource.js"></script>
<script src="resources/js/lib/angular/angular-route.js"></script>
<script src="resources/js/mainApp.js"></script>
<script src="resources/js/InsuranceAddController.js"></script>
</head>
<body>
<p id="wrapper">
<p ng-view></p>
</p>
</body>
</html>
Then create an add.html routing page
<p class="row">
....
</p>
Then mainApp.js, the js used to control route distribution and templates
var mainApp = angular.module('mainApp', [ 'ngRoute', 'ngResource' ]);
mainApp.config([ '$routeProvider', function($routeProvider) {
$routeProvider.when('/add.do', {
templateUrl : 'insurance_add.html',
controller : 'InsuranceAddController'
});
} ]);
Then create InsuranceAddController.js for handling some js or other of add.html page
mainApp.controller('InsuranceAddController', ['$scope', '$location', function($scope, $location) {
$scope.gotoList = function() {
...
};
}]);
What I want to achieve is to write a paging on this page, and my understanding is to write a controller on this routing page,
<p class="row">
<p ng-controller="PaginationDemoCtrl">
...
</p>
</p>
Then add the code for controlling PaginationDemoCtrl in InsuranceAddController.js
mainApp.controller('InsuranceAddController', ['$scope', '$location', function($scope, $location) {
$scope.gotoList = function() {
...
};
}]);
angular.module('ui.bootstrap.demo', ['ngAnimate', 'ui.bootstrap']);
angular.module('ui.bootstrap.demo').controller('PaginationDemoCtrl', function ($scope, $log) {
...
});
However, an error is reported. How can this be achieved? (Foolish question from a newbie, please bear with me)
The following is the paging DEMO (I want to throw the paging demo into the add.html routing page)
<p ng-controller="PaginationDemoCtrl">
<uib-pagination total-items="bigTotalItems" ng-model="bigCurrentPage" max-size="maxSize" class="pagination-sm" boundary-link-numbers="true">
</uib-pagination>
</p>
<script>
angular.module('ui.bootstrap.demo', ['ngAnimate', 'ui.bootstrap']);
angular.module('ui.bootstrap.demo').controller('PaginationDemoCtrl', function ($scope, $log) {
$scope.totalItems = 64;
$scope.currentPage = 4;
$scope.setPage = function (pageNo) {
$scope.currentPage = pageNo;
};
$scope.pageChanged = function() {
$log.log('Page changed to: ' + $scope.currentPage);
};
$scope.maxSize = 5;
$scope.bigTotalItems = 175;
$scope.bigCurrentPage = 1;
});
</script>
I can tell you exactly how to use it
controller
是没有问题,出错说明你什么地方写错了,比如:在哪里定义的PaginationDemoCtrl
?Also, write a pagination, why do you need to put another one inside it
controller
?Where does the mainApp here come from? Can the browser recognize it correctly?