如下面的代碼所示,分頁(來自用於引導庫的Angular指令)控件的存在會在初始加載時將模型的值更改爲1,有沒有辦法解決?我添加了一個Plunker here。分頁控制更改了模型的值,它必須與1
<!DOCTYPE html>
<html>
<head>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet">
</head>
<body ng-app="testApp" ng-controller="testCtrl">
<pagination ng-model="currentPage"></pagination>
</body>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.17/angular.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-bootstrap/0.11.0/ui-bootstrap-tpls.min.js"></script>
<script>
var testApp = angular.module('testApp', ['ui.bootstrap']);
var testCtrl = function($scope) {
$scope.currentPage = 4;
$scope.$watch('currentPage', function(){
alert($scope.currentPage);
});
}
testCtrl.$inject = ['$scope'];
testApp.controller('testCtrl', testCtrl);
</script>
</html>
感謝
你可以發佈演示演示你的問題。根據文檔和這個plunker它的工作原理,因爲你期望設置當前頁面爲4:http://plnkr.co/edit/mBJMyohp1JQI3LBqRLkr?p=preview – lucuma
上面提供的代碼是一個完整的演示,但我會複製它爲了方便 – JMK