AngularJS Essentials
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
Creating Reusable Components with Directives<br />
The ngBindHtml directive<br />
Sometimes, it might be necessary to bind a string of raw HTML. In this case, the<br />
ngBindHtml directive can be used in the same way as ngBind; however, the only<br />
difference will be that it does not escape the content, which allows the browser to<br />
interpret it as shown in the following code:<br />
index.html<br />
<br />
<br />
<br />
[Packt] Parking<br />
<br />
<br />
<br />
var parking = angular.module("parking", []);<br />
parking.controller("parkingCtrl", function ($scope) {<br />
$scope.appTitle = "[Packt] Parking";<br />
});<br />
<br />
<br />
<br />
<br />
<br />
<br />
In order to use this directive, we will need the angular-sanitize.js dependency.<br />
It brings the ngBindHtml directive and protects the application against common<br />
cross-site scripting (XSS) attacks.<br />
The ngRepeat directive<br />
The ngRepeat directive is really useful to iterate over arrays and objects. It can be<br />
used with any kind of element such as the rows of a table, the elements of a list, and<br />
even the options of select.<br />
We must provide a special repeat expression that describes the array to iterate over<br />
the variable that will hold each item in the iteration. The most basic expression<br />
format allows us to iterate over an array, attributing each element to a variable:<br />
variable in array<br />
[ 22 ]<br />
www.it-ebooks.info