【发布时间】:2017-01-17 17:39:48
【问题描述】:
我是 Angular js 的新手。我开发了一个登录应用程序。我创建了一个登录表单,其中有登录按钮。点击登录按钮我想 导航到 home.html 页面我使用了 $location.path('/home') 但它被附加到现有的 url 但没有被显示。有人能帮我吗 有了这个
Index.js:在此我使用 routeconfig 定义了路由。
var myapp = angular
.module("mainModule", ['ngRoute'])
.config(function ($routeProvider, $locationProvider) {
$routeProvider
.when("/login", {
templateUrl: "Templates/login.html",
controller: "LoginController",
controllerAs: "loginctrl",
caseInsensitiveMatch: true
})
.when("/Home", {
templateUrl: "Templates/Home.html",
controller: "HomeController",
controllerAs: "Homectrl",
caseInsensitiveMatch: true
})
})
.controller("LoginController", function ($scope, $location) {
$scope.username = "";
$scope.password = "";
$scope.Login = function () {
if ($scope.username == "a" || $scope.password == "a") {
alert("SuccessFully Logged in")
$location.path("/Home");
}
//alert('Hello'+$scope.username+""+$scope.password);
}
})
.controller("HomeController", function ($scope) {
})
登录.html
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" ng-app="mainModule">
<head>
<title></title>
<script src="../Scripts/angular.js"></script>
<script src="../Scripts/angular-route.js"></script>
<script src="../index.js"></script>
</head>
<body>
<div ng-controller="LoginController">
<table>
<tbody>
<tr>
<th>UserName:</th>
<th><input type="text" value="" ng-model="username" /></th>
</tr>
<tr>
<th>Password:</th>
<th><input type="password" value="" ng-model="password" /></th>
</tr>
<tr>
<th><button name="Submit" ng-click="Login()"> Submit</button>
</tr>
</tbody>
</table>
</div>
</body>
</html>
主页.Html
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml ng-app=" mainmodule">
<head>
<title></title>
<script src="../Scripts/angular.js"></script>
<script src="../Scripts/angular-route.js"></script>
<script src="../index.js"></script>
</head>
<body ng-controller="HomeController">
hi
</body>
</html>
网址生成为:http://localhost:40613/Templates/Login.html#/Home 所以,Home.html 的路由是如上生成的,而不是http://localhost:40613/Templates/Home.html 请帮我解决这个问题
【问题讨论】: