16.07.2017 Views

AngularJS Essentials

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 2<br />

The ngClass directive<br />

The ngClass directive is used every time you need to dynamically apply a class to<br />

an element by providing the name of the class in a data-binding expression. The<br />

following code shows the application of the ngClass directive:<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 />

.selected {<br />

background-color: #FAFAD2;<br />

}<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

Plate<br />

Entrance<br />

<br />

<br />

<br />

[ 27 ]<br />

www.it-ebooks.info

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

Saved successfully!

Ooh no, something went wrong!