Note that there are some explanatory texts on larger screens.

plurals
  1. POAngularJS Paging with $location.path but no ngView reload
    text
    copied!<p>My single page application loads a home page and I want to display a series of ideas. Each of the ideas is displayed in an animated flash container, with animations displayed to cycle between the ideas. </p> <p>Ideas are loaded using $http:</p> <pre><code>$scope.flash = new FlashInterface scope:$scope,location:$location $http.get("/competition.json") .success (data) -&gt; $scope.flash._init data </code></pre> <p>However, to benefit from history navigation and UX I wish to update the address bar to display the correct url for each idea using $location:</p> <pre><code>$location.path "/i/#{idea.code}" $scope.$apply() </code></pre> <p>I am calling $apply here because this event comes from outwith the AngularJS context ie Flash. I would like for the current controller/view to remain and for the view to not reload. This is very bad because reloading the view results in the whole flash object being thrown away and the preloader cycle beginning again.</p> <p>I've tried listening for $routeChangeStart to do a preventDefault:</p> <pre><code>$scope.$on "$routeChangeStart", (ev,next,current) -&gt; ev.preventDefault() $scope.$on "$routeChangeSuccess", (ev,current) -&gt; ev.preventDefault() </code></pre> <p>but to no avail. The whole thing would be hunky dory if I could figure out a way of overriding the view reload when I change the $location.path.</p> <p>I'm still very much feeling my way around AngularJS so I'd be glad of any pointers on how to structure the app to achieve my goal!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload