2016-12-19 117 views
0

我從來沒有遇到過這個問題,我知道這是一個小問題......但我似乎無法弄清楚什麼是錯誤的......我的部分1沒有正確加載,而是它擊中否則路線回到我的/登錄(我分配)。 每當我點擊創建一個調查鏈接,它會將我重定向回登錄名,並且URL顯示這個http://localhost:3000/#!/login#%2Fcreate,但是當我將http://localhost:3000/#!/create放入其工作的URL中時。不太清楚問題是什麼。請幫忙!角度部分不工作

var app = angular.module('myApp', ['ngRoute']); 
 

 
app.config(function($routeProvider){ 
 
\t $routeProvider 
 
\t .when('/login', { 
 
\t \t templateUrl: 'partials/login.html', 
 
\t \t controller: 'UserController' 
 
\t }) 
 
\t .when('/dashboard', { 
 
\t \t templateUrl: 'partials/dashboard.html', 
 
\t \t controller: 'SurveyController' 
 
\t }) 
 
\t .when('/create', { 
 
\t \t templateUrl: 'partials/create.html', 
 
\t \t controller: 'SurveyController' 
 
\t }) 
 
\t .when('/poll/:id', { 
 
\t \t templateUrl: 'partials/poll.html' 
 
\t }) 
 
\t .otherwise({ 
 
\t \t redirectTo: '/login' 
 
\t }); 
 
})
<!DOCTYPE html> 
 
<html> 
 
<head> 
 
\t <title>Survey Polls</title> 
 
\t <!-- CSS --> 
 
\t <link rel="stylesheet" href="bootstrap/dist/css/bootstrap.css"> 
 
    <link rel="stylesheet" type="text/css" href="styles.css"> \t 
 
\t <!-- Angular --> 
 
\t <script src="angular/angular.js"></script> 
 
\t <script src="angular-route/angular-route.js"></script> 
 
\t <!-- jQuery/Bootstrap --> 
 
\t <script src="jquery/dist/jquery.js"></script> 
 
\t <script src="bootstrap/dist/js/bootstrap.js"></script> 
 
\t <!-- App.js --> 
 
\t <script src="app.js"></script> 
 
\t <!-- Controllers/Factories --> 
 
\t <script src="controllers/SurveyController.js"></script> \t 
 
\t <script src="controllers/UserController.js"></script> 
 
\t <script src="factories/SurveyFactory.js"></script> 
 
\t <script src="factories/UserFactory.js"></script> 
 
</head> 
 
<body ng-app="myApp"> 
 
\t <div class="container"> 
 
\t \t <div ng-view></div> 
 
\t </div> 
 
</body> 
 
</html> 
 

 

 

 

 
<a href="#/create">Create a new survey</a> 
 

 
<h3>Current polls:</h3> 
 

 
<table border="1"> 
 
\t <thead> 
 
\t \t <tr> 
 
\t \t \t <th>Name</th> 
 
\t \t \t <th>Survey Question</th> 
 
\t \t \t <th>Date Posted</th> 
 
\t \t \t <th>Action</th> 
 
\t \t </tr> 
 
\t </thead> 
 
\t <tbody> 
 
\t \t <tr ng-repeat="s in surveys"> 
 
\t \t \t <td>{{ s._user.username }}</td> 
 
\t \t \t <td>{{ s.question }}</td> 
 
\t \t \t <td>{{ s.created_at }}</td> 
 
\t \t \t <td><button ng-show="loggedInUser._id == s._user._id" ng-click="delete(s._id)">Delete</button></td> 
 
\t \t </tr> 
 
\t </tbody> 
 
</table>

+0

哪一個不工作創建? – Yaser

+0

是的,對不起,我編輯了我的帖子。哎呦! –

+0

向我們展示瞭如何導航以創建狀態...觸發它的功能。 – Thalaivar

回答

0

嘗試使用NG-的href,而不是僅僅HREF。 希望有幫助

+0

所以它會是Create a new survey

+0

我已經爲你創造了一個蹲點,只是一個簡單的和鏈接工作正常請看看https://plnkr.co/edit/q4Bamm2was76KeBknkC7?p=preview –

+0

它工作時,我改變了一個href爲「#!/創建」,但爲什麼我的網址有「!」在裏面? –

0

我發現了一個可能的解決方案here。添加此行到您的配置擺脫感嘆號(!):

$locationProvider.hashPrefix(''); 
+0

非常感謝! :) –

+0

很高興幫助。 – Mickers