我使用javaScript
的onsubmit功能重定向到基於角色特定的頁面。我也是在我app.but使用AngularJS
當我按下填寫表單的頁面直接去那個頁面,而不是在ng-view
加載頁面後輸入。我該如何解決這個問題?我如何可以重定向到頁面採用了棱角分明的JS,而我使用JavaScript window.location的
代碼:
function next(){
var role = location.search.substring(1);
if (role == "vp"){
//alert ("Login successfully");
window.location = "results.html?vp";//redirecting to other page
//return false;
}
else{
window.location = "results-locked.html?sales";
}
}
角JS
var module = angular.module("portalApp", ['ngRoute']);
module.config(['$routeProvider',
function($routeProvider) {
$routeProvider.
when('/home', {
templateUrl: 'home.html',
}).
when('/results', {
templateUrl: 'results.html',
}).
when('/lock-results', {
templateUrl: 'results-locked.html',
}).
otherwise({
redirectTo: '/home'
});
}]);
HTML:
<div class="search-form">
<form method="post" name="myform" action="javascript:next()" class="ourform">
<img src="images/mic.png" class="mic">
<input type="search" id="search" name="search" placeholder="Type or speak here to search">
<input type="image" alt="submit" src="images/search.jpg" class="submit"/>
</form>
</div>
,而不是我要像在JavaScript href="#/results"
和href="#/results-locked"
一些事情。
你可以顯示你的HTML嗎?代碼,放置錨點。 –
使用$ location.path(); – user3227295
您應該使用'ngSubmit'指令以及'$ location.path();' – Satpal