【发布时间】:2017-11-23 18:40:04
【问题描述】:
我是 AngularJS 的新手。
我尝试提交一个简单的表单。从服务器获得响应后,我想重定向到另一个页面(仪表板)。我的 url 被重定向了,但页面没有被重定向。
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 按钮,我的网址将更改为http://localhost:8585/#!/dashboard。但我不知道如何路由到仪表板的页面。另外,在我的网址中,为什么会变成#!?
提前致谢。
【问题讨论】:
-
你应该考虑使用 ngRoute
-
编辑和分享代码。会有帮助的。
标签: javascript html angularjs express angular-routing