Book Image

Learning Single-page Web Application Development

Book Image

Learning Single-page Web Application Development

Overview of this book

Table of Contents (15 chapters)
Learning Single-page Web Application Development
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

The AngularJS MVC pattern implementation


AngularJS follows the MVC pattern of software engineering and encourages loose coupling between presentation, data, and logic components. However, in the AngularJS framework, we do not declare the model as in other MVC libraries such as Ember.js and Backbone.js.

In AngularJS, we declare the model within the controller, through the use of $scope. Let's check the MVC behavior inside AngularJS in the upcoming sections.

Model

AngularJS Model can be considered as a JavaScript object or a primitive JavaScript type such as string, number, boolean, or complex objects.

Synthesizing its definition, AngularJS Model is a JavaScript object inside controllers using $scope. The properties and behaviors that represent the object can be accessed by its respective View.

Later, we will go deeper in to the use of $scope; for now, let's see a simple example:

function UserController($scope) {
  // A simple JavaScript object to hold our Model
  var user;

  user = {
    // User...