I had a list of objects defined in my controller, and was sorting it after vm.init()
like this:
const myItems = [{},{},{}...{}]
vm.init().then(function() {
$scope.ajaxLoading = true; // Loader
$scope.itemsToRender = [];
// Pushing items from myItems in this list according to some conditions
$scope.itemsToRender.sort(function(a, b) {
return a.order - b.order;
})
}).finally(function() {
$scope.ajaxLoading = false;
});
This was working fine as expected,
but now I am getting myList
from api response in vm.init()
, and it does not sort the list when I come to this page. But if I reload the page, it sorts the list and renders perfectly.
I tried debugging and put console.log in the function, and the function was being called.
What am I doing wrong? Is the list rendering before sorting is complete? How do I fix this?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…