问题
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="janesemail@gmail.com" 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>
回答1:
Your routes don't include '/projectname', which I assume is your application context. You need to include that in the route urls for it to work properly.
回答2:
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
来源:https://stackoverflow.com/questions/28744335/unable-to-redirect-using-angular-routeprovider