我有一个棱角分明的单页应用程序,可以正确加载主页和有关页面。但是编辑路径陷入了无限的错误循环。
错误是
SyntaxError:意外令牌'<'
我使用editCaldera()
表格中的按钮调用ng-click
<table class="table">
<thead>
<tr>
<th scope="col">id</th>
<th scope="col">Borrower1</th>
<th scope="col">Email</th>
<th scope="col">Address</th>
<th scope="col">ContactNumber</th>
<th scope="col">Lender</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="caldera in calderas">
<td>{{ caldera._id }}</td>
<td>{{ caldera.Borrower1 }}</td>
<td>{{ caldera.Email }}</td>
<td>{{ caldera.Address }}</td>
<td>{{ caldera.ContactNumber }}</td>
<td>{{ caldera.Lender }}</td>
<td><button ng-click="editCaldera(caldera._id)">Edit</button></td>
<td><button ng-click="deleteCaldera(caldera._id)">Delete</button></td>
</tr>
</tbody>
</table>
下面是我的主要javascript文件。
var calderaApp = angular.module('calderaApp', ['ngRoute']);
calderaApp.config(function($locationProvider, $routeProvider) {
$locationProvider.html5Mode(true);
$routeProvider
// route for the home page
.when('/', {
templateUrl: 'pages/home.html',
controller: 'mainController'
})
// route for the about page
.when('/about', {
templateUrl: 'pages/about.html',
controller: 'aboutController'
})
.when('/edit/:id', {
templateUrl: 'pages/edit.html',
controller: 'editController'
})
});
calderaApp.controller('mainController', function($scope, $http, $location) {
// when landing on the page, get all todos and show them
$http.get('/findall')
.success(function(data) {
console.log(data);
$scope.calderas = data;
})
.error(function(data) {
console.log('Error: ' + data);
});
// when submitting the add form, send the text to the node API
$scope.editCaldera = function(id) {
console.log('editCaldera function')
var earl = '/edit/' + id;
$location.url(earl);
};
});
calderaApp.controller('aboutController', function($scope, $http) {
$scope.message = 'Look! I am an about page.';
});
calderaApp.controller('editController', function($scope, $http, $routeParams) {
console.log('edit')
});
我需要id字段来进行API调用,但是甚至在进行此调用之前,甚至在使用非常基本的控制器的情况下,都会发生循环。