2015-05-21 9 views
1

我使用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"一些事情。

+0

你可以顯示你的HTML嗎?代碼,放置錨點。 –

+0

使用$ location.path(); – user3227295

+1

您應該使用'ngSubmit'指令以及'$ location.path();' – Satpal

回答

0

我在兩種模式hashbang模式和HTML5模式解決了這個通過修改JavaScript代碼

function next(){ 
    var role = location.search.substring(1); 
    if (role == "vp"){ 
     //alert ("Login successfully"); 
     window.location = "#/results";//redirecting to other page 
     //return false; 
    } 
    else{ 
     window.location = "#/lock-results"; 
    } 
} 
0

嗨angularjs作品。

可以從鏈接瞭解詳細內容

https://docs.angularjs.org/guide/ $位置

所以如果你的錨標記,如果您使用

<a href="home.html">go to home</a> 

它不會工作,所以你必須 激活所需的模式,或者你可以直接使用在#href屬性

<a href="#home.html">go to home</a>