michaelbromley / michaelbromley/angularUtils
dirPagination (v.0.11.1) pages.length failed on firefox 50.1.0 with asynchronous setup
- Dominant language
- JavaScript
- Stars
- 2k
- Forks
- 842
- PR merge metrics
- No merged PRs in 30d
Description
**Description of issue**:
I use es6 syntax, and webpack for my angular project. I import controllers as classes, and I use dirPagination directive to paginate results from api. it works fine on all browsers but firefox. I tried to compile directive after I get content, but the result was the same, directive initializes, but for some reason pages.length failed to update.
**Demo**: (for dirPagination, fork and modify this Plunk:
no demo is present since I use es6, with ng-annotate and it will be time consuming to reproduce it
Any relevant code:
*this is my method for pagination initialization in my controller (es6 syntax):*
```javascript
export class PretragaProfiliAdvokatiController {
constructor ($routeParams, $http, $location, $scope, $filter, $timeout, $compile, $document, urls, ProfileSearchService, paginationService ) {
'ngInject';
this.$routeParams = $routeParams;
this.$http = $http;
this.$location = $location;
this.$scope = $scope;
this.$filter = $filter;
this.$timeout = $timeout;
this.$compile = $compile;
this.$document = $document;
this.urls = urls;
this.ProfileSearchService = ProfileSearchService;
this.paginationService = paginationService;
//pagination setup
this.advokati = [];
this.totalAdvokati = undefined;
this.advokatiPerPage = 15; // this should match however many results your API puts on one page
this.order = 'prezime';
this.reverseSort = false;
this.searchFiltersAdvokati = this.ProfileSearchService.searchFiltersAdvokati;
this.pagination = {
current: 1
};
this.getQueries();
}
getQueries() {
const query = this.$location.search();
//check if page number has been set
if (query.hasOwnProperty('p')) {
this.pagination.current = query.p;
}
//check if search term has been set, if yes, get the results
if (query.hasOwnProperty('termin')) {
this.searchTerm = {};
if (query.termin !== '') {
this.searchTerm.preslovljen = this.$filter('preslovljivac')(query.termin, 'sr_RS@cyrillic');
this.searchTerm.original = query.termin;
} else {
this.searchTerm.preslovljen = '';
this.searchTerm.original = '';
}
}
if (angular.isDefined(this.searchTerm)) {
console.log(this.pagination.current, this.advokatiPerPage, this.order, this.reverseSort);
// I console the current pagination settings
this.getResultsPage(this.pagination.current, this.advokatiPerPage, this.order, this.reverseSort);
// get the results and set pagination
}
}
getResultsPage(Page, itemsPerPage, orderBy, reverseSort) {
const searchTerm = this.searchTerm;
const filters = this.searchFiltersAdvokati;
this.$http.post(`${this.urls().BASE_API}/advokati_search`, {Page, itemsPerPage, orderBy, reverseSort, searchTerm, filters})
.then((result) => {
this.advokati = result.data.Items; //data items
this.totalAdvokati = result.data.Total; //total items for pagination
this.instancializePagination(); //compile pagination directive and expect it to show on the page
});
}
instancializePagination() {
const elem = ``;
this.$timeout(() => {
console.log(this.$document[0].querySelector('.pagination'));
angular.element(this.$document[0].querySelector('.pagination')).append(this.$compile(elem)(this.$scope));});
}
pageChanged(newPage) {
this.$location.search('p', newPage);
this.getResultsPage(newPage, this.advokatiPerPage, this.order, this.reverseSort);
}
}
```
for unknown reason to me it fails in firefox, with no error thrown.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start at getResultsPage and instancializePagination, especially the asynchronous $timeout, $compile, and DOM append path shown in the report. Reproduce the pagination initialization with asynchronous API results in Firefox and compare it with other browsers. Done means pages.length updates reliably and pagination renders after setup without requiring a missing reproduction demo.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- angularjs, javascript, webpack
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 20/100