16.07.2017 Views

AngularJS Essentials

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Dependency Injection and Services<br />

{{car.plate}}<br />

Color<br />

{{car.color}}<br />

Entrance<br />

{{car.entrance | date:'dd/MM/yyyy hh:mm'}}<br />

Period<br />

{{ticket.period}}<br />

Price<br />

{{ticket.price | currency}}<br />

Depart<br />

Back to parking<br />

Changing the location<br />

There are many ways to navigate, but we need to identify where our resource is<br />

located before we decide which strategy to follow. In order to navigate within the<br />

route mechanism, without refreshing the page, we can use the $location service.<br />

There is a function called path that will change the URL after the #, allowing the<br />

application to be a single-page one.<br />

However, sometimes, it might be necessary to navigate out of the application<br />

boundaries. It could be done by the $window service by means of the location.href<br />

property as follows:<br />

controller.js<br />

parking.controller("carController", function ($scope, $routeParams,<br />

$location, $window, parkingHttpFacade, parkingService) {<br />

$scope.depart = function (car) {<br />

parkingHttpFacade.deleteCar(car)<br />

.success(function (data, status) {<br />

$location.path("/parking");<br />

})<br />

.error(function (data, status) {<br />

$window.location.href = "error.html";<br />

});<br />

};<br />

var retrieveCar = function (id) {<br />

parkingHttpFacade.getCar(id)<br />

.success(function (data, status) {<br />

$scope.car = data;<br />

$scope.ticket = parkingService.calculateTicket(car);<br />

})<br />

.error(function (data, status) {<br />

[ 92 ]<br />

www.it-ebooks.info

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!