O'Reilly logo

Learning AngularJS by Ken Williamson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 7. AngularJS Models

AngularJS models are held in the $scope object. In AngularJS, $scope is used to gain access to the model related to a particular controller. $rootScope is a parent scope that can be used to save and access model properties that span multiple controllers. The use of $rootScope is highly discouraged in most designs, however. There is only one $rootScope in an application. $scope is a child scope of $rootScope.

A properly designed AngularJS application will have little or no use for $rootScope to store model properties. In this chapter we will focus only on $scope, used to store the model retrieved from REST services.

Public REST Services

The REST services used for this chapter are available at http://nodeblog-micbuttoncloud.rhcloud.com/NodeBlog. The services are open to the public and written in JavaScript using Node.js, ExpressJS, and MongoDB. In Chapter 11, you will deploy the same REST services with your AngularJS blog application as a MEAN stack (MongoDB, ExpressJS, AngularJS, and Node.js) application. You will then deploy the MEAN stack to the cloud using a free RedHat OpenShift account.

The following excerpt shows how AngularJS services access the REST services used for this chapter. The REST services return the same JSON that was previously hardcoded in the controllers:

/* chapter7/services.js excerpt */

$resource(
  "http://nodeblog-micbuttoncloud.rhcloud.com/NodeBlog/blog/:id" 
  ...
$resource(
  "http://nodeblog-micbuttoncloud.rhcloud.com/NodeBlog/blogList" ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required