重定向到Angular JS中的另一个HTML页面
Redirect to another HTML page in Angular JS
我编写了一个没有实际服务器的简单登录表单。只是一个硬编码的登录凭据。如果它们的凭据在angular controller函数上匹配,那么我需要显示另一个HTML页面。在"/login.html"上,编写了以下代码
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Login</title>
<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="font-awesome/css/font-awesome.css" rel="stylesheet">
<link href="css/animate.css" rel="stylesheet">
<link href="css/style.css" rel="stylesheet">
<script type="text/javascript" src="/InfoGraph/js/angular/angular.min.js" ></script>
<script type="text/javascript" src="/InfoGraph/js/angular/angular-route.min.js" ></script>
<script type="text/javascript" src="/InfoGraph/js/login.js" ></script>
</head>
<body class="gray-bg" ng-app="login">
<div class="middle-box text-center loginscreen animated fadeInDown">
<div>
<div>
<h1 class="logo-name">IGraph</h1>
</div>
<h3>Welcome to IGraph</h3>
<form class="m-t" role="form" name="loginToIGraph" ng-controller="LoginController as login">
<div class="form-group">
<input type="text" class="form-control" placeholder="Username" required="" ng-model="user.username" >
</div>
<div class="form-group">
<input type="password" class="form-control" placeholder="Password" required="" ng-model="user.password" >
</div>
<button type="submit" class="btn btn-primary block full-width m-b" ng-click="login.loginUser(user)">Login</button>
<a href="#"><small>Forgot password?</small></a>
<p class="text-muted text-center"><small>Do not have an account?</small></p>
<a class="btn btn-sm btn-white btn-block" href="register.html">Create an account</a>
</form>
</div>
</div>
</body>
</html>
在"login.js
"中,代码如下:
(function(){
var app = angular.module('login',[]);
app.controller('LoginController', ['$scope','$location', function($scope,$location)
{
$scope.loginUser = function(user){
if(user.username == 'demo' && user.password == 'demo'){
$location.href('/afterLogin.html');
}
else{
alert('Wrong credentials')
}
}
}]);
})();
但在$location.href('/afterLogin.html');
上,它什么也没做。即使没有错误。原因可能是什么?
你能这样试试吗:
var path = "/afterLogin.html";
window.location.href = path;
您可以使用angular$窗口。就像短信在之前的重定向回答中所说的那样。
另一种方法是通过Routing-ngRoute或ui路由器
这可能会对您有所帮助。使用$location 重定向至AngularJS中的新页面
Giving proper path will help you I think.
相关文章:
- 使用javascript将动态表从一个html页面打印到另一个html页
- 将html元素插入到文本字符串中,以匹配另一个html字符串
- 如何在另一个html文件的框架中包含图像
- 重定向到Angular JS中的另一个HTML页面
- 使用JavaScript打开另一个html页面时传递变量
- 如何在另一个 html 标签内选择 web 元素硒 Web 驱动程序与 html 源
- 显示从 HTML 表单到另一个 HTML 表单的发布值
- 收到事件时加载另一个.html页面
- 为什么谷歌跟踪代码管理器不能安装在正文下的另一个HTML元素中
- 获取另一个html标记下的html元素值
- 使用angularjs将HTML表单数据从页面提交到另一个HTML页面
- 在我的html页面-web应用程序用户界面的一个选项卡中的另一个html页面中的选项卡
- 调用另一个HTML文件中的函数
- 如何从使用jquery load()加载的另一个html页面执行在主html文件中编写的脚本
- 将NG打印的数据在一个html中重复传输到另一个html
- 在href跳转到另一个html元素之前,执行Knockout.js数据绑定:点击函数
- 用javascript(不带外部文件)将html加载到另一个html中
- 正在检测Html元素是否与另一个Html元件重叠
- 如何在屏幕大小上将html文件更改为另一个html文件
- 禁用来自另一个html页面的html框架的超链接