The Relationship Between Scope and Back-End Server Data

Often data that is used for an AngularJS application comes from a back-end data source such as a database. In such instances, the scope still acts as the definitive source of data for the AngularJS application. You should use the following rules when interacting with data that is coming from the server side:

■ Access data from the database or other back-end sources via AngularJS services, which are discussed in Chapter 9, “Implementing AngularJS Services in Web Applications.” This includes both reading and updating data.

■ Ensure that data read from the server updates the scope, which in turn updates the view. Avoid the temptation to manipulate the HTML values directly from the database, which can lead to the scope becoming out of sync with the view.

■ Reflect changes that are made to the database or other back-end source in scope as well. You can do this by first updating the scope and then updating the database using a service, or you can update the database and then use the results from the database to repopulate the appropriate values in the scope.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset