0

I have a form that I need to submit, if something goes wrong I would like to show an error page, I have a controller and view for this but I would like for the browser location textbox not to change to avoid the user from bookmarking the error page.

So I would have a page called /Items

the user submits and there was an error so I would like to show this page (itemsError.html) to the user but I don't want to allow the user to bookmark /ItemsError

If I plugin into the routeprovider then the browser location bar is going to update with something like /ItemsError and at a later date the user could bookmark the page, but this page is a dynamic page and should only be shown depending on the result of the form submission.

What is Angular's best practice for supporting something like this?

Thanks

4

1 回答 1

0

配置.js

$routeProvider.when('/', {
  template: '/views/home.html',
});

索引.html

<!doctype html>
<html lang="en" ng-controller="app">
<head>
</head>
<body>
<ng-include src="page"></ng-include>
</body>
</html>

控制器.js

controller('app', ['$scope','$route',function($scope,$route) {
  $scope.$on("$routeChangeSuccess",function($currentRoute,$previousRoute){
    $scope.page = $route.current.template;
  });
}]).

这将处理您的一般路由。现在您可以根据逻辑动态交换控制器中的部分。在您的示例中,如果表单未成功完成,您的错误回调可以即时更改部分:

controller('form', ['$scope','$route',function($scope,$route) {
  $scope.submit = function(){
    something.get().$then(
       function( value ){$scope.page = '/views/successPage.html/';},
       function( error ){$scope.page = '/views/errorPage.html/';}
    )
  }
}]).
于 2013-07-26T14:11:35.357 回答