<h1>{{header}}</h1> <a ng-href="{{back.url}}">{{back.text}}</a> <div ng-view></div>
In my module configuration
$routeProvider. when('/', { controller:HomeCtrl, templateUrl:'home.html' }). when('/menu', { controller:MenuCtrl, templateUrl:'menu.html' }). when('/items', { controller:ItemsCtrl, templateUrl:'items.html' }). otherwise({ redirectto:'/' });
Controllers
function HomeCtrl($scope, $rootScope){ $rootScope.header = "Home"; $rootScope.back = {url:'#/menu', text:'Menu'}; } function MenuCtrl($scope, $rootScope){ $rootScope.header = "Menu"; $rootScope.back = {url:'#/', text:'Back'}; } function ItemsCtrl($scope, $rootScope){ $rootScope.header = "Items"; $rootScope.back = {url:'#/', text:'Back'}; }
As you can see in my controllers, I hardcoded the return URL and text (in fact, I don't need text, like an image). Thus, I found that in some cases the button does not move correctly. I cannot use the history.back() button coz my back to go to the menu link in the home view.
So my question is how to get the previous route route in controllers or the best way to achieve this?
I created a Plunker demo of my problem. Please check it.
angularjs angularjs-routing
Gihan Mar 02 '13 at 14:09 2013-03-02 14:09
source share