2017-11-23 1 views
0

AngularJS를 처음 사용했습니다.AngularJS 양식 제출 후 다른 페이지로 리디렉션

간단한 양식을 제출하려고했습니다. 서버에서 응답을 받으면 다른 페이지 (대시 보드)로 리디렉션하고 싶습니다. 내 URL이 리디렉션되지만 페이지는 리디렉션되지 않습니다.

index.html을 :

<!DOCTYPE html> 
<html ng-app="myApp"> 
    <head> 
    <meta charset="utf-8"> 
    <title>index page</title> 
    <script src="bower_components/angular/angular.min.js"></script> 
    <script src="bower_components/angular-route/angular-route.min.js"> 
</script> 
    <script type="text/javascript" src="front/controller/controller.js"> 
</script> 
    </head> 
    <body> 
    <div ng-controller="myCtrl"> 
     <p>Today's welcome message is:</p> 
     <form novalidate> 
     <input type="text" ng-model="name"> 
     <input type="password" ng-model="passwww"> 
     <button type="button" ng-click="btn()" name="button">submit</button> 
     </form> 
    </div> 
    </body> 
</html> 

Controller.js : 나는이 submit 버튼을 클릭하면

var app = angular.module('myApp', []); 
app.controller('myCtrl',function ($scope,$http,$location) { 
    $scope.btn = function() { 
    var nam = $scope.name; 
    var pass = $scope.passwww; 
    var detail ={ 
     "name" : nam, 
     "password" : pass 
     } 
     console.log(nam + " and1 " + pass); 
    $http({ 
    url : "/daaa", 
    method : "post", 
    data : detail, 
    headers : {'Content-Type' : 'application/json'} 
    }) 
    .then(function (response) { 
    $location.path('/dashboard'); 
    console.log($location.path()); 
    }).catch(function (response) { 
    console.error("error in posting"); 
    }); 
    }; 
}); 

, 내 URL을 http://localhost:8585/#!/dashboard로 변경됩니다. 하지만 대시 보드의 페이지로 연결하는 방법을 모르겠습니다. 또한 내 URL에 왜 #!이 될까요?

미리 감사드립니다.

+0

당신은 ngRoute – Sajeetharan

+0

을 사용하여 코드를 편집하고 공유해야합니다. 도움이 될 것입니다. – SaRaVaNaKR

답변

0

는 다음을 사용할 수 있습니다 당신은 자바 스크립트에서 직접 window.location = 'newurl'을 설정할 수 있습니다

<form onsubmit="window.location.href='type://your.url/here';" novalidate> 
관련 문제