The route mechanism also allows us to pass parameters. In order to obtain the passed parameter inside the controller, we need to inject the
$routeParams
service, which will provide us with the parameters passed through the URL.
controller.js
snippet
parking.controller("carController", function($scope, $routeParams,
parkingHttpFacade, parkingService) {
$scope.depart = function(car) {
parkingHttpFacade.deleteCar(car)
.success(function(data, status) {
$scope.message = "OK";
})
.error(function(data, status) {
$scope.message = "Something went wrong!";
});
};
var retrieveCar = function(id) {
parkingHttpFacade.getCar(id)
.success(function(data, status) {
$scope.car = data;
$scope.ticket = parkingService.calculateTicket(car);
})
.error(function(data, status) {
$scope.message = "Something went wrong!";
});
};
retrieveCar($routeParams.id);
});
car.html
<h3>Car Details</h3>
<h5>Plate</h5> {{car.plate}}
<h5>Color</h5> {{car.color}}
<h5>Entrance</h5> {{car.entrance | date:'dd/MM/yyyy hh:mm'}}
<h5>Period</h5> {{ticket.period}}
<h5>Price</h5> {{ticket.price | currency}}
<button ng-click="depart(car)">Depart</button>
<a href="#/parking">Back to parking</a>