简体   繁体   English

后退按钮angularjs问题

[英]Back button angularjs issue

I have this routing code for my app 我的应用有此路由代码

app.config(function ($routeProvider) {
            $routeProvider
                .when('',
                    {
                        controller:'competitionsController',
                        templateUrl:'competitions.html'
                    })
                .when ('/teams/',
                    {
                        controller:'teamsController',
                        templateUrl:'teams.html'
                    })
                .when('/squad/',
                    {
                        controller:'squadController',
                        templateUrl:'squad.html'
                    })
                .when('/player/',
                    {
                        controller:'playerController',
                        templateUrl:'player.html'
                    })
                .otherwise('');
        });

The order I display the information follows like that Competitions/Teams/squad/player 我显示信息的顺序如下:比赛/团队/小队/球员

It works perfectly until I click in the navigator back button from squad or player pages, where it doesn't work well, it throws a "error loading pages" and it return to the competitions page. 直到我在小队或球员页面中单击导航器的后退按钮时,它才能正常运行,在该页面中效果不佳,它将抛出“错误加载页面”,并返回到竞赛页面。 What I'm doing wrong? 我做错了什么?

You can check the behaviour of this here: http://balonmano100.p.ht/prueba/ 您可以在此处检查此行为: http : //balonmano100.p.ht/prueba/

Thanks 谢谢

You're setting your url via the href attribute in your link tag. 您是通过链接标记中的href属性设置网址的。 Try using ng-click and the $location object to set the browser's url. 尝试使用ng-click$location对象设置浏览器的url。

<div ng-controller="myCtrl">
    <a href="#" ng-click="goTo('myUrlPart')">My Link</a>
</div>

Then in your controller 然后在您的控制器中

angular.module('myApp',[])
    .controller('myCtrl',['$scope','$location',function($scope,$location){
        $scope.goTo = function(url){
            $location.path(url);
        }; // end goTo
    }]); // end myCtrl / myApp

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM