[英]Redirect to another page after form submit in AngularJS
我是AngularJS的新手。
我试图提交一个简单的表格。 从服务器获得响应后,我想重定向到另一个页面(仪表板)。 我的网址已重定向,但页面未重定向。
index.html :
<!DOCTYPE html>
<html ng-app="myApp">
<head>
<meta charset="utf-8">
<title>index page</title>
<script src="bower_components/angular/angular.min.js"></script>
<script src="bower_components/angular-route/angular-route.min.js">
</script>
<script type="text/javascript" src="front/controller/controller.js">
</script>
</head>
<body>
<div ng-controller="myCtrl">
<p>Today's welcome message is:</p>
<form novalidate>
<input type="text" ng-model="name">
<input type="password" ng-model="passwww">
<button type="button" ng-click="btn()" name="button">submit</button>
</form>
</div>
</body>
</html>
Controller.js :
var app = angular.module('myApp', []);
app.controller('myCtrl',function ($scope,$http,$location) {
$scope.btn = function () {
var nam = $scope.name;
var pass = $scope.passwww;
var detail ={
"name" : nam,
"password" : pass
}
console.log(nam + " and1 " + pass);
$http({
url : "/daaa",
method : "post",
data : detail,
headers : {'Content-Type' : 'application/json'}
})
.then(function (response) {
$location.path('/dashboard');
console.log( $location.path());
}).catch(function (response) {
console.error("error in posting");
});
};
});
如果单击“ submit
按钮,则URL更改为http:// localhost:8585 /#!/ dashboard 。 但是我不知道如何路由到仪表板的页面。 另外,在我的网址中,为什么它变成#!
?
提前致谢。
您可以使用以下内容:
<form onsubmit="window.location.href='type://your.url/here';" novalidate>
您可以直接在javascript中设置window.location = 'newurl'
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.