角度局部不起作用

时间:2016-12-19 21:56:44

标签: angularjs partials

我之前从未遇到过这个问题,我知道这是一个很小的问题......但是我似乎无法弄清楚出了什么问题...我的部分内容没有正确加载而是碰到了否则回到我的/登录(我已分配)。 每次我点击创建调查链接时,它都会将我重定向回登录,并且网址会显示http://localhost:3000/#!/login#%2Fcreate,但是当我将http://localhost:3000/#!/create放入网址时,它会正常工作。不太确定问题是什么。请帮忙!



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

app.config(function($routeProvider){
	$routeProvider
	.when('/login', {
		templateUrl: 'partials/login.html',
		controller: 'UserController'
	})
	.when('/dashboard', {
		templateUrl: 'partials/dashboard.html',
		controller: 'SurveyController'
	})
	.when('/create', {
		templateUrl: 'partials/create.html',
		controller: 'SurveyController'
	})
	.when('/poll/:id', {
		templateUrl: 'partials/poll.html'
	})
	.otherwise({
		redirectTo: '/login'
	});
})

<!DOCTYPE html>
<html>
<head>
	<title>Survey Polls</title>
	<!-- CSS -->
	<link rel="stylesheet" href="bootstrap/dist/css/bootstrap.css">
    <link rel="stylesheet" type="text/css" href="styles.css">	
	<!-- Angular -->
	<script src="angular/angular.js"></script>
	<script src="angular-route/angular-route.js"></script>
	<!-- jQuery/Bootstrap -->
	<script src="jquery/dist/jquery.js"></script>
	<script src="bootstrap/dist/js/bootstrap.js"></script>
	<!-- App.js -->
	<script src="app.js"></script>
	<!-- Controllers/Factories -->
	<script src="controllers/SurveyController.js"></script>	
	<script src="controllers/UserController.js"></script>
	<script src="factories/SurveyFactory.js"></script>
	<script src="factories/UserFactory.js"></script>
</head>
<body ng-app="myApp">
	<div class="container">
		<div ng-view></div>
	</div>
</body>
</html>




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

<h3>Current polls:</h3>

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

2 个答案:

答案 0 :(得分:0)

尝试使用ng-href而不仅仅是href。 希望有所帮助

答案 1 :(得分:0)

我找到了一个可能的解决方案here。将此行添加到您的配置中以消除感叹号(!):

$locationProvider.hashPrefix('');