我有一个angularJS应用程序,它使用服务在3个控制器之间共享数据。我使用html表单中的按钮在视图之间路由。表单的action属性设置为目标路由的URL。在Chrome中使用HTML表单操作更改路线(AngularJS)
在Firefox似乎没有成为一个问题,但镀铬插入一个问号到URL,这似乎重新启动应用程序并删除共享服务:
火狐结果:
“HTTP://本地主机/对myApp /应用/#/ thirdScreen”(没问题)
铬结果:
“HTTP://本地主机/对myApp /应用/#/ THI rdScreen“(丢弃服务,应用程序似乎重新启动并且共享服务数据丢失)。
但是,连续来回连续数次似乎解决了Chrome中剩余应用程序生命周期的问题。
- 问号是什么意思?
- 是否必须使用我的控制器中的$ location服务来改变路线,还是有另一种方法?
谢谢!
的Html
//Extract from the bottom of the secondScreen.html partial
<div class="col-md-12 column">
<form action="#/thirdScreen">
<button type="submit" class="btn btn-lg btn-block btn-danger">
Go to third page
</button>
</form>
</div>
App.js
angular.module('myApp', [
'myApp.services',
'myApp.directives',
'myApp.controllers',
'myApp.filters',
'ngRoute'
]).
config(['$routeProvider', '$locationProvider', function($routeProvider, $locationProvider) {
$routeProvider.
when("/firstScreen", {templateUrl: "partials/firstScreen.html", controller: 'firstScreenController'}).
when("/secondScreen", {templateUrl: "partials/secondScreen.html", controller:"secondScreenController"}).
when("/thirdScreen", {templateUrl: "partials/thirdScreen.html", controller:"thirdScreenController"}).
otherwise({redirectTo: '/firstScreen'});
}]);
Controllers.js
controller('secondScreenController', function($scope, $http, sessionDetailsService, modalService, goodsCheckedInFetchingService) {
$scope.session = sessionDetailsService;
}).
controller('thirdScreenController', function($scope, $http, sessionDetailsService, modalService, goodsCheckedInFetchingService) {
$scope.session = sessionDetailsService;
}).
使用,适用于角导航是没有意义的 – charlietfl 2014-09-03 11:44:44
请澄清一下,是不是因为你应该只使用一种形式提交数据到服务器并加载新页面?我没有使用href的原因是因为它没有被允许在一个按钮元素中,可能我错了吗? – emmet 2014-09-03 12:10:04
为什么不使用''标签? – charlietfl 2014-09-03 12:11:21