我有一个带有ng-click的按钮,我通过paramater将一个对象传递给一个函数,该函数必须将我重定向到另一个页面,其中包含我传递给它的对象的id,另一个控制器接收它,在bd中搜索它并在我的视图中显示它,但是它不起作用的按钮,它只是将我重新检索到$ routeProvicer.otherwise('/')。但如果我输入manualy localhost:3000 / admin / 1241245124< = id它完美无缺......
任何帮助都是相关的,我已经把你留在了我的代码。
admin.html
<h1>Admin Panel</h1>
<hr>
<div class="row">
<div class="col-md-6">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">Productos</h3>
</div>
<div class="panel-body">
<table class="table">
<tr>
<td>Titulo</td>
<td>Tipo</td>
<td>Autor</td>
<td>Creado</td>
<td>Acciones</td>
</tr>
<tr ng-repeat="product in products">
<td><a ng-href="{{}}">{{product.nombre}}</a></td>
<td>{{product.tipo}}</td>
<td>{{product.autor}}</td>
<td>{{product.creado | date}}</td>
<td><a href="#" class="btn btn-warning" ng-click="deleteBook(product)">Borrar</a> <a href="#" class="btn btn-info" ng-click="editBook(product)">Editar</a></td>
</tr>
</table>
</div>
</div>
</div>
<div class="col-md-6">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">Articulos</h3>
</div>
<div class="panel-body">
Panel content
</div>
</div>
</div>
</div>
admin.js
'use strict';
angular.module('myApp.admin', ['ngRoute'])
.config(['$routeProvider', function($routeProvider) {
$routeProvider.when('/admin', {
templateUrl: 'admin/admin.html',
controller: 'AdminCtrl'
});
$routeProvider.when('#/admin/:id', {
templateUrl: 'admin/edit.html',
controller: 'AdminEditCtrl'
});
}])
.controller('AdminCtrl', function($scope, $http,librosFactory, $location) {
librosFactory.getLibros().success(function(libros){
$scope.products = libros;
});
$scope.deleteBook = function(book){
console.log(book);
librosFactory.deleteBook(book).success(function (book,err) {
if (err) console.log(err);
else console.log("libro borrado");
});
};
$scope.editBook = function (book) {
if(book._id) {
console.log(book);
$location.url('#/admin/'+book._id);
}
else {
console.log('erroror');
}
}
})
.controller('AdminEditCtrl', function ($scope, $routeParams, librosFactory) {
librosFactory.searchById($routeParams.id).success(function (book, err) {
if(err) console.log(err);
console.log(book)
$scope.product = book;
})
});
答案 0 :(得分:1)
尝试从<a>
中的href属性中删除#,让它为href=""