Reputation: 6123
I have an Angular project where in one view you have a list of orders, of those orders you will see only the title, once you click on that title, you should be redirected by the list.id
to a new view where you would see the full content of the order.
This is the html where you should see the title of that order
<a ng-href="#/orders/{{list.id}}" ng-repeat="list in detalleOrden">
<h5>Orden {{list.id}}</h5>
<p>{{list.unidadEjec}}</p>
</a>
and here the HTML where you should see the full content of the order. Watch the HTML above ng-href="#/orders/{{list.id}}"
<table class="table">
<tbody>
<tr>
<th>Supervisor</th>
<td ng-bind="list.supervisor"></td>
</tr>
<tr>
<th>Responsable:</th>
<td>{{list.responsable}}</td>
</tr>
<tr>
<th>Solicitante:</th>
<td>{{list.solicitante}}</td>
</tr>
<tr>
<th>Unidad ejecutora:</th>
<td>{{list.unidadEjec}}</td>
</tr>
</tbody>
</table>
in that I am not using any ng-repeat, should I ?
here the code:
$routeProvider
.when('/orders', {
templateUrl: 'views/main.html',
controller: 'OrderDetailsCtrl',
resolve: {
orders: function(Order) {
return Order.list();
}
}
})
.when('/orders/:id', {
templateUrl: 'views/order-detail.html',
controller: 'OrderIdCtrl',
resolve: {
order: function(Order, $routeParams) {
Order.list().then(function(orders) {
for(var i = 0; i < orders.length; i++) {
if(orders[i].id === $routeParams.id) {
return orders[i];
}
}
return null;
});
}
}
})
controllers
.controller('OrderDetailsCtrl', function ($scope, $routeParams, $log, $rootScope, Order) {
Order.list().then(function(orders) {
$scope.detalleOrden = orders;
}
});
.controller('OrderIdCtrl', function ($scope, $routeParams, $log, $rootScope, Order) {
$scope.order = {};
Order.list().then(function(orders) {
for(var i = 0; i < orders.length; i++) {
if(orders[i].id === $routeParams.id) {
$scope.order = orders[i];
}
}
}, function() {
$log('error');
});
});
and here the service
.factory('Order', function ($q) {
return {
list: function() {
var deferred = $q.defer();
deferred.resolve([{
id: '12423',
title: 'Detalles de la orden',
supervisor: 'Someone',
responsable: 'Someone Else',
solicitante: 'Recope',
unidadEjec: 'Grupo Planificador Belén'
}, {
id: '56456',
title: 'Detalles de la orden',
supervisor: 'Carlos Blabla',
responsable: 'Alberto Blablo',
solicitante: 'Recope',
unidadEjec: 'Grupo VEINSA'
}]);
return deferred.promise;
}
};
});
so, my issue: when I click on the title of the order, I am successfully redirected to the new view, but I am unable to visualize the content.
Upvotes: 1
Views: 77
Reputation: 8589
You don't need to use any ng-repeat
and just use order
instead, look:
<table class="table">
<tbody>
<tr>
<th>Supervisor:</th>
<td>{{order.supervisor}}</td>
</tr>
<tr>
<th>Responsable:</th>
<td>{{order.responsable}}</td>
</tr>
<tr>
<th>Solicitante:</th>
<td>{{order.solicitante}}</td>
</tr>
<tr>
<th>Unidad ejecutora:</th>
<td>{{order.unidadEjec}}</td>
</tr>
</tbody>
</table>
Upvotes: 1
Reputation: 2534
AFAIK you have to use variable order
instead of list
in table
. Am thinking that table
is in detailed view.
For the uri /orders/:id
you have order
variable in controller OrderIdCtrl
.
Upvotes: 0