Tôi đang cố gắng tạo một chỉ thị phân trang đơn giản với một phạm vi riêng biệt. Đối với một số lý do khi tôi thay đổi giá trị theo cách thủ công, giá trị này hơi khó tính. Đây là vấn đề của tôi:Ngõ vào đầu vào AngularJS không cập nhật
Khi tôi chuyển tiếp và lùi, nó hoạt động rất tốt. Awesome
Khi tôi nhập một trang vào trường nó hoạt động. Tuyệt vời
Tuy nhiên, nếu tôi nhập một trang vào trường và sau đó thử tiến lên và lùi, kiểu ng có vẻ sẽ bị ngắt sau khi tôi nhập một trang vào trường. Tôi đã có nó làm việc khi tôi không cô lập phạm vi của tôi nhưng tôi bối rối là tại sao nó sẽ phá vỡ nó. Đây là mã của tôi:
HTML:
<paginate go-to-page="goToPage(page)" total-pages="results.hits.pages" total-hits="results.hits.total"></paginate>
Chỉ thị:
'use strict';
angular.module('facet.directives')
.directive('paginate', function(){
return {
restrict: 'E',
template: '<div class="pull-right" ng-if="(totalPages !== undefined) && (totalPages > 0)">'+
'<span class="left-caret hoverable" ng-click="changePage(current-1)" ng-show="current > 1"></span> Page'+
' <input type="number" ng-model="current" class="pagination-input" ng-keypress="enterPage($event)"/> of'+
' {{totalPages}} '+
'<span class="right-caret hoverable" ng-click="changePage(current+1)" ng-show="current < totalPages"></span>'+
'</div>',
scope: {
goToPage: '&',
totalPages: '=',
totalHits: '='
},
link: function(scope) {
scope.current = 1;
scope.changePage = function(page) {
scope.current = page;
window.scrollTo(0,0);
scope.goToPage({page:page});
};
scope.enterPage = function(event) {
if(event.keyCode == 13) {
scope.changePage(scope.current);
}
}
}
}
});
Tôi đang làm gì sai?
bạn có thể thiết lập một jsFiddle hoặc Plunkr? –