AngularJS view does not change when navigating a link
What puzzles me is the following: I have a simple link:
<li><a href="#/foo">Foos</a></li> but when you click on it, the view is not updated. The URL in the browser changes, but nothing happens and nothing is displayed in the console. If I load the URL directly in the browser, the correct page will load.
Routes are as follows:
app.config(function($routeProvider, RestangularProvider) { $routeProvider .when('/index', {templateUrl: 'assets/views/index.html'}) .when('/foos', {templateUrl: 'assets/views/list.html', controller: controllers.FooListCtrl}) .when('/foos/create', {templateUrl: 'assets/views/update.html', controller: controllers.FooUpdateCtrl}) .when('/foos/:id/update', {templateUrl: 'assets/views/update.html', controller: controllers.FooUpdateCtrl}) .otherwise({redirectTo: '/index'}); RestangularProvider.setBaseUrl("/admin"); }); Good, therefore, apparently, this is a known sorting problem : when a locationProvider (i.e. $location ) is entered to a single controller, links stop working all over the world. One way to solve the problem is to rewrite the links through jQuery, and this works:
app.run(function($rootScope) { $('[ng-app]').on('click', 'a', function() { window.location.href = $(this).attr('href'); }); });