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 />

},<br />

templateUrl: "alert.html",<br />

replace: true<br />

};<br />

});<br />

alert.html<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

The left-hand side contains the name of the parameter available inside the directive's<br />

scope to be used in the template. The right-hand side contains the name of the<br />

attribute declared in the element, whose value will contain the expression to link to<br />

the property on the directive's template. By prefixing it with @, the literal value will<br />

be used as a parameter.<br />

Following this, we are using the = prefix in order to create a bidirectional relationship<br />

between the controller and the directive. It means that every time anything changes<br />

inside the controller, the directive will reflect these changes:<br />

index.html<br />

<br />

<br />

controllers.js<br />

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

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

$scope.alertTopic = "Something went wrong!";<br />

$scope.alertMessage = "You must inform the plate and the color<br />

of the car!";<br />

});<br />

directives.js<br />

[ 39 ]<br />

www.it-ebooks.info

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

Saved successfully!

Ooh no, something went wrong!