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.

Scope<br />

The scope is an object that acts as a shared context between the view and the<br />

controller that allows these layers to exchange information related to the application<br />

model. Both sides are kept synchronized along the way through a mechanism called<br />

two-way data binding.<br />

In this chapter, we are going to cover the following topics:<br />

• Two-way data binding<br />

• Best practices using the scope<br />

• The $rootScope object<br />

• Broadcasting the scope<br />

Two-way data binding<br />

Traditional web applications are commonly developed through a one-way data<br />

binding mechanism. This means there is only a rendering step that attaches the data<br />

to the view. This is done with the following code snippet in the index.html file:<br />

<br />

Show Plate<br />

Consider the following code snippet in the render.js file:<br />

var plate = "AAA9999";<br />

$("#plate").val(plate);<br />

$("#showPlate").click(function () {<br />

alert(plate);<br />

});<br />

www.it-ebooks.info

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

Saved successfully!

Ooh no, something went wrong!