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.

[ 25 ]<br />

Chapter 2<br />

The ngClick directive and other event<br />

directives<br />

The ngClick directive is one of the most useful kinds of directives in the framework.<br />

It allows you to bind any custom behavior to the click event of the element. The<br />

following code is an example of the usage of the ngClick directive calling a function:<br />

index.html<br />

<br />

<br />

<br />

[Packt] Parking<br />

<br />

<br />

var parking = angular.module("parking", []);<br />

parking.controller("parkingCtrl", function ($scope) {<br />

$scope.appTitle = "[Packt] Parking";<br />

$scope.cars = [];<br />

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

car.entrance = new Date();<br />

$scope.cars.push(car);<br />

delete $scope.car;<br />

};<br />

});<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

Plate<br />

Entrance<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

www.it-ebooks.info

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

Saved successfully!

Ooh no, something went wrong!