简体   繁体   English

访问新页面后上一页会上移

[英]previous page moves up after visting a new page

i'm building an ionic app and there is a back link that always links users back to the previous page. 我正在构建一个离子应用程序,并且有一个向后链接,该链接始终将用户链接回上一页。 what i've noticed is when the user scrolls to the middle or the buttom of a page and click on a new url and then uses the back button on the url to come back to the previous page, the page will automatically start from the top again. 我注意到的是,当用户滚动到页面的中间或底部并单击新的URL,然后使用URL上的“后退”按钮返回到上一页时,该页面将自动从顶部开始再次。 When i test on pc, the state maintains its state but when i deployed to an android phone i found this happening? 当我在PC上进行测试时,状态保持其状态,但是当我将其部署到Android手机时,我发现这种情况发生了吗?

JS JS

.controller('back_ctrl', function($scope, $ionicHistory) 
{
   $scope.goBack=function()
    {
        $ionicHistory.goBack();                      //This doesn't work
        //window.history.back();                     //This works
        //alert('goBackHandler called. Did it work?'); //For testing
    };
})

HTML 的HTML

 <ion-nav-buttons side="left">
   <button class="button button-icon icon ion-chevron-left" ng-controller="back_ctrl" ng-click="goBack()"> </button> 
   </ion-nav-buttons>

Why you're trying to create controller for this one.. Ionic gave this feature as default. 为什么要尝试为此创建控制器。Ionic将此功能作为默认设置。

Could you try this out: 您可以尝试一下:

    <!-- Header Start -->
        <ion-nav-bar class="bar-stable">

            <ion-nav-buttons side="left">
                <i class="fa fa-navicon"></i>                    
            </ion-nav-buttons>
            <ion-nav-back-button></ion-nav-back-button>
            <h1 class="title"></h1>
            <ion-nav-buttons side="right">
                <i class="fa fa-search"></i>              
            </ion-nav-buttons>

        </ion-nav-bar>                        
        <!-- Header End -->

So, The ion-nav-back-button will appear when the user is able to go back in the current navigation stack. 因此,当用户能够返回当前导航堆栈时,将显示ion-nav-back-button By default, the markup of the back button is automatically built using platform-appropriate defaults (iOS back button icon on iOS and Android icon on Android). 默认情况下,后退按钮的标记是使用适合平台的默认值(iOS上的iOS后退按钮图标和Android上的Android图标)自动构建的。

Additionally, the button is automatically set to $ionicGoBack() on click/tap. 此外,单击/轻击按钮会自动设置为$ionicGoBack() By default, the app will navigate back one view when the back button is clicked. 默认情况下,单击后退按钮时,该应用程序将在后视图中导航。

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

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