当前位置: 动力学知识库 > 问答 > 编程问答 >

javascript - AngularJS adding content to the routing for a back button

问题描述:

.when('/football', {

templateUrl : 'assets/pages/football/home.html',

controller : 'footballController'

})

.when('/football/teams', {

templateUrl : 'assets/pages/football/teams.html',

controller : 'footballController'

})

I have the above to route my application, but I'm curious if there is a way to set a variable here?

I have a navbar in the application that has a back button, I'd like to set a string so that if someone is on /football/teams and clicks back, it will take them to /football instead of using history .back()

If possible it would be easier to be able to do this from the routing section

网友答案:

you could try to use resolve param of when method:

.when('/football', {
    templateUrl : 'assets/pages/football/home.html',
    controller  : 'footballController'
    resolve: {
            setVar: function ($route, dataService) {
                return dataService.set($route.current.params.id);
            }
        }
})

dataService - it's your own service to share the state of variables.

Here you could find an example: http://jsfiddle.net/derkoe/Wk7WD/presentation/

分享给朋友:
您可能感兴趣的文章:
随机阅读: