历史后退导航采用NG-包括: [英] History back navigation using ng-include

查看:139
本文介绍了历史后退导航采用NG-包括:的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我就开始发展同angularjs单个页面的Web应用程序,现在我定义导航。所以,我最终会使用2级导航:

I started to develop a single page web app with angularjs and now I'm defining the navigation. So, I end up using 2 levels of navigation:

1级:采用NG-视图主导航

1st level: Main navigation using ng-view.

2级:子视图导航使用NG-包括顶部和底部的酒吧

2nd level: SubView navigation with the top and bottom bars using ng-include.

这是我们的iPhone的场景:

This is our iphone scenario:

而iphone的情况似乎确定了我,因为我们控制了所有的导航与我们的按钮。 但是,现在让我们觉得在Android的情况下,用户可以使用历史后退按钮(物理按键)导航回来。我们如何能够支持它,如果我们使用NG-包括子导航?

The iphone scenario seems ok for me because we control all navigation with our buttons. But, now lets think in android scenario where the user can use the history back button(physical button) to navigate back. How can we support it if we use ng-include for the subnavigation?

在此先感谢

推荐答案

您可以将参数添加到您的网址,使之与Android的历史工作。

You could add a parameter to your URL to make it work with Android history.

#/main?page=1
#/main?page=2

然后使用以控制您的应用程序的状态,然后回的android按钮将工作。

Then use that to control the state of your app, and then android back button will work.

您可以设置URL参数与 $ location.search

You can set url parameters with $location.search:

$location.search('page', 4);

$ location.search文档: http://docs.angularjs.org/api /ng.$location#search

还有一件事:你要添加 reloadOnSearch:假选择您的 $ routeProvider.when()声明视图。默认情况下,整个视图重新加载,当您更改与 $ location.search的查询参数()。即设置为false将使其不会重新加载,这是你想在这种情况下,是什么:

And one more thing: You'll want to add reloadOnSearch: false option to your $routeProvider.when() declaration for your view. By default, the whole view reloads when you change a query parameter with $location.search(). Setting that to false will make it not reload, which is what you want in this case:

$routeProvider.when('/main', { reloadOnSearch: false });

reloadOnSearch文档: http://docs.angularjs.org/api/ng。 $ routeProvider#当

这篇关于历史后退导航采用NG-包括:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆