问题描述
我是新来的角度我,当我不能够重定向到signup.html页面时,我打的locahost:端口/项目名称/
eventhough我指定的模板的URL singup在app.js我得到404
但是当我打的locahost:端口/项目名称/ signup.html文件被打开难道我做错了什么。
我想要得到的signup.html当我打的locahost:端口/项目名称/
app.js
VAR应用= angular.module('pollApp',['ngRoute']);
的app.config(['$ routeProvider',函数($ routeProvider){
$ routeProvider
。当('/欢迎',{
templateUrl:/Welcome.html',
控制器:'submitCtrl
})
。什么时候('/', {
templateUrl:/signup.html',
控制器:'submitCtrl
})
。除此以外({
redirectTo:/Welcome.html
});
}]);
submitController.js
app.controller('submitCtrl',['$范围,$ HTTP,$位置', 功能($范围,$ HTTP,$位置){
$ scope.timeZones = [
{标签:(GMT-09:00)阿拉斯加',值:阿拉斯加},
{标签:(GMT-08:00)太平洋时间(美国和放大器;放大器;加拿大)',值:太平洋时间(美国和放大器;放大器;加拿大)'}
];
$ scope.submit =功能(){
VAR为userDetails =新的对象();
userDetails.firstname = $ scope.firstname;
userDetails.lastname = $ scope.lastname;
userDetails.Companyname = $ scope.Companyname;
userDetails.Email = $ scope.Email;
userDetails.timezone = $ scope.timezone;
的console.log(为userDetails);
$ HTTP({
方法:POST,
数据:为userDetails,
网址:'/ mongopractise / REST /注册/用户数据,
标题:{内容类型:应用/ JSON'}
})。成功(功能(数据,状态,头,配置){ 的console.log(成功的数据+ JSON.stringify(数据));
$ scope.username =数据;
$ location.url('/ Welcome.html')。取代();; })。
错误(功能(数据,状态,头,配置){
的console.log(故障数据+数据);
});
} }]);
Signup.html
< HTML LANG =ENNG-应用=pollApp>
< HEAD>
<间的charset =UTF-8>
< META HTTP-EQUIV =X-UA-Compatible的内容=IE =边缘>
< META NAME =视口CONTENT =WIDTH =设备宽度,初始规模= 1>
<标题>!欢迎< /标题> &所述; SCRIPT SRC =LIB / angular.js>&下; /脚本>
<链接HREF =CSS / bootstrap.min.css的rel =stylesheet属性>
< DIV CLASS =容器NG-控制器='submitCtrl'> <窗体类=形横角色=形式>
< DIV CLASS =表单组>
<标签类=COL-LG-3控制标签>首先名称:LT; /标签>
< DIV CLASS =COL-LG-8>
<输入类=表格控VALUE =简式=文本模式NG- =名字>
< / DIV>
< / DIV>
< DIV CLASS =表单组>
<标签类=COL-LG-3控制标签>姓:< /标签>
< DIV CLASS =COL-LG-8>
<输入类=表格控VALUE =主教类型=文本NG模型=姓氏>
< / DIV>
< / DIV>
< DIV CLASS =表单组>
<标签类=COL-LG-3控制标签>公司:其中; /标签>
< DIV CLASS =COL-LG-8>
<输入类=表格控VALUE =类型=文本NG模型=公司名称>
< / DIV>
< / DIV>
< DIV CLASS =表单组>
<标签类=COL-LG-3控制标签>电子邮件:< /标签>
< DIV CLASS =COL-LG-8>
<输入类=表格控VALUE [email protected]类型=文本NG模型=电子邮件>
< / DIV>
< / DIV>
< DIV CLASS =表单组>
<标签类=COL-LG-3控制标签>时区:LT; /标签>
< DIV CLASS =COL-LG-8>
< DIV CLASS =UI选>
<选择一个id =user_time_zone级=表格控NG模型=时区NG选项=时区作为timeZones.label在时区时区> < /选择>
< / DIV>
< / DIV>
< / DIV> < DIV CLASS =COL-MD-8>
<输入类=BTN BTN-主要NG点击='提交()'值=保存更改类型=按钮> <跨度类=>< / SPAN> <输入类=BTN BTN-默认值=取消TYPE =复位>
< / DIV>
< / DIV>
< /表及GT; < /头>
< / HTML>
你的端口之后的任何路径预计将在 routeProvider
配置。您应该断绝的服务的项目名的文件夹,然后
。当('/',{templateUrl:/signup.html',
控制器:'submitCtrl
})
将如预期
i am new to angular i when i am not able to redirect to the signup.html page when i hit the locahost:port/projectname/
eventhough i specified the template url for singup in app.js i am getting 404
but when i hit the locahost:port/projectname/signup.html the file was opening am i doing anything wrong?
i want to get the signup.html when i hit locahost:port/projectname/
app.js
var app = angular.module('pollApp', ['ngRoute']);
app.config(['$routeProvider',function($routeProvider){
$routeProvider
.when('/Welcome', {
templateUrl: '/Welcome.html',
controller: 'submitCtrl'
})
.when('/', {
templateUrl: '/signup.html',
controller: 'submitCtrl'
})
.otherwise({
redirectTo: '/Welcome.html'
});
}]);
submitController.js
app.controller('submitCtrl',['$scope', '$http', '$location',
function ($scope, $http, $location) {
$scope.timeZones = [
{ label: '(GMT-09:00) Alaska', value: 'Alaska' },
{ label: '(GMT-08:00) Pacific Time (US & Canada)', value: 'Pacific Time (US & Canada)' }
];
$scope.submit=function() {
var userDetails=new Object();
userDetails.firstname=$scope.firstname;
userDetails.lastname=$scope.lastname;
userDetails.Companyname=$scope.Companyname;
userDetails.Email=$scope.Email;
userDetails.timezone=$scope.timezone;
console.log(userDetails);
$http({
method: 'POST',
data: userDetails,
url:'/mongopractise/rest/signup/userdata',
headers: {'Content-Type':'application/json'}
}).success(function(data, status, headers, config) {
console.log("success data"+JSON.stringify(data));
$scope.username=data;
$location.url('/Welcome.html').replace();;
}).
error(function(data, status, headers, config) {
console.log("Failure data"+data);
});
}
}]);
Signup.html
<html lang="en" ng-app="pollApp">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Welcome!</title>
<script src="lib/angular.js"></script>
<link href="css/bootstrap.min.css" rel="stylesheet">
<div class="container" ng-controller='submitCtrl'>
<form class="form-horizontal" role="form">
<div class="form-group">
<label class="col-lg-3 control-label">First name:</label>
<div class="col-lg-8">
<input class="form-control" value="Jane" type="text" ng- model="firstname">
</div>
</div>
<div class="form-group">
<label class="col-lg-3 control-label">Last name:</label>
<div class="col-lg-8">
<input class="form-control" value="Bishop" type="text" ng-model="lastname">
</div>
</div>
<div class="form-group">
<label class="col-lg-3 control-label">Company:</label>
<div class="col-lg-8">
<input class="form-control" value="" type="text" ng-model="Companyname">
</div>
</div>
<div class="form-group">
<label class="col-lg-3 control-label">Email:</label>
<div class="col-lg-8">
<input class="form-control" value="[email protected]" type="text" ng-model="Email">
</div>
</div>
<div class="form-group">
<label class="col-lg-3 control-label">Time Zone:</label>
<div class="col-lg-8">
<div class="ui-select">
<select id="user_time_zone" class="form-control" ng-model="timezone" ng-options="timeZones as timeZones.label for timeZones in timeZones">
</select>
</div>
</div>
</div>
<div class="col-md-8">
<input class="btn btn-primary" ng-click='submit()' value="Save Changes" type="button"> <span class=""></span>
<input class="btn btn-default" value="Cancel" type="reset">
</div>
</div>
</form>
</head>
</html>
Any path after your port is expected to be in routeProvider
config. your sever should serve the projectname folder then
.when('/', {templateUrl: '/signup.html',
controller: 'submitCtrl'
})
will work as expected
这篇关于无法采用了棱角分明routeprovider重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!