[英]How can I handle back button on pages with templates?
I am working on a site using angularjs. 我在使用angularjs的网站上工作。 I divide the page into two section: menu and content. 我将页面分为两部分:菜单和内容。
for example 例如
this a page: /mainpage 这个页面:/ mainpage
<div>
<div id="menu">
<div ng-click="setTemplate('firstPage.html')">Page 1</div>
<div ng-click="setTemplate('secondPage.html')">Page 2</div>
<div ng-click="setTemplate('thirdPage.html')">Page 3</div>
</div>
<div id="content" ng-template="template">
</div>
</div>
controller: 控制器:
$scope.template = 'firstPage.html';
$scope.setTemplate = function(value){
$scope.template = value;
}
So after click on Page 1 Then Page 2 Then Page 3. So when i click on the back button, it load the last page / but not /mainpage with the right template. 因此,在单击第1页然后单击第2页然后单击第3页之后。因此,当我单击“后退”按钮时,它将使用正确的模板加载最后一页/而不是/ mainpage。 How would i handle the back button to not go back to previous page and go to previous template if there was a template change? 如果发生模板更改,我将如何处理后退按钮以不返回上一页并转到上一个模板?
Thanks. 谢谢。
You should look at https://github.com/angular-ui/ui-router . 您应该查看https://github.com/angular-ui/ui-router 。 You could build the functionality yourself, but ui-router is pretty much where you will end up. 您可以自己构建功能,但是ui-router几乎可以实现最终目标。
The problem is you have nothing for it to default to. 问题是您没有默认设置。 When you click back, it's just loading /mainpage, but it has no template to load in. Usually you use a $routeprovider for this: 当您单击返回时,它只是加载/ mainpage,但没有要加载的模板。通常,您可以使用$ routeprovider进行此操作:
$routeProvider
.when('/',
{
controller: 'yourControllerName.js',
templateUrl:'mainpage.html'
})
.otherwise(
{
redirectTo : '/'
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.