javascript - Fire event when route is unchanged angularjs -
i want perform reload of route when there's not route change, in other words reload controller when button takes route clicked. in view in ng-click directive call following method:
this.reload = function() { $scope.$on('$routechangestart', function(event, next, current) { if($route.current == $route.next) { $route.reload(); } }) }
the code inside condition never triggered because there's not change in route. i'm beginner in angularjs, appreciated :)
i handle 2 things mentioned above separately.
- on each route change whatever want do.
register event listener listens routechangestart.
$rootscope.$on('$routechangestart', function (event, next, prev) { //if logic given want next/prev objects });
- if user clicks button reload route.
html
<button ng-click="reload_route()">reload</button>
controller
app.controller('myctrl', function($scope, $route){ $scope.reload_route = function(){ //once again add if logic in here if needed $route.reload(); } })
also, in above example $routechangestart function executes callback , passed event, next, , prev objects. should using arguments in if statements, not $route.current or $route.next.
Comments
Post a Comment