angularjs - $location.search being changed automatically, cannot manually set either -
angularjs - $location.search being changed automatically, cannot manually set either -
edit: reset/typeerror due not specifying reloadonsearch: false
in route. pagination trying redirect page default value (1
), telling page load results in $timeout
solved this.
i'm having rather annoying error in angularjs @ moment.
i'm trying & set specific search parameter:
var searchparams = $location.search(); $scope.limit = searchparams.limit > 0 ? searchparams.limit : 10; $scope.currentpage = searchparams.page > 0 ? searchparams.page : 1;
this gets parameter fine, if load page parameters except defaults there (10 , 1), automatically reload (triggering controller twice) using defaults.
additionally, when set search query myself:
$scope.changepage = function() { $location.search('page', $scope.currentpage); getusers(); };
it causing next typeerror: cannot read property 'add' of undefined
error:
typeerror: cannot read property 'add' of undefined @ resolveelementclasses (http://localhost:8080/site/bower_components/angular-animate/angular-animate.js:480:22) @ http://localhost:8080/site/bower_components/angular-animate/angular-animate.js:1028:27 @ http://localhost:8080/site/bower_components/angular-animate/angular-animate.js:469:22 @ scope.$digest (http://localhost:8080/site/bower_components/angular/angular.js:13324:36) @ scope.$apply (http://localhost:8080/site/bower_components/angular/angular.js:13540:24) @ htmlanchorelement.<anonymous> (http://localhost:8080/site/bower_components/angular/angular.js:21697:23) @ htmlanchorelement.eventhandler (http://localhost:8080/site/bower_components/angular/angular.js:2986:21) (anonymous function) angular.js:10683 (anonymous function) angular.js:7858 scope.$digest angular.js:13326 scope.$apply angular.js:13540 (anonymous function) angular.js:21697 eventhandler angular.js:2986
here's total controller - loads users pagination - in theory nil complicated:
app.controller('userctrl', ['$scope', '$location', 'user', function ($scope, $location, user) { // url if present, else set defaults var searchparams = $location.search(); $scope.limit = searchparams.limit > 0 ? searchparams.limit : 10; $scope.currentpage = searchparams.page > 0 ? searchparams.page : 1; var getusers = function() { $scope.loading = true; $scope.users = null; user.one().get({ 'limit': $scope.limit, 'offset': ($scope.currentpage - 1) * $scope.limit }).then(function(resp) { $scope.loading = false; $scope.users = resp.data; $scope.users_count = resp._meta.total_count; }); }; getusers(); $scope.changepage = function() { $location.search('page', $scope.currentpage); getusers(); }; }]);
i can't see wrong here, maybe i'm missing something.
controller triggers twice if manually going route url search param (eghttp:/site/users?page=2
trigger, instantly reload http://site/users?page=1
) setting search param when changing page causes typeerror
. angularjs
Comments
Post a Comment