concept scope in category ionic

appears as: scope, scope, The scope, scopes, scopes
Ionic in Action: Hybrid Mobile Apps with Ionic and AngularJS

This is an excerpt from Manning's book Ionic in Action: Hybrid Mobile Apps with Ionic and AngularJS.

We’ll cover a bit about Angular in chapter 3 to get you up and running, but this isn’t a book about Angular. You’ll want to refer to the books AngularJS in Action (http://manning.com/bford) and AngularJS in Depth (http://manning.com/aden) to learn everything you want about Angular beyond the scope of this book.

The result of adding a controller will give the controller a particular region on the page that it has access to, as you can see later in figure 3.5. For example, you need to be able to manage how you load the data and attach it to the scope. You can reset the project to step3 if you’re using Git:

Figure 3.5. The controller’s scope can only apply to markup inside of the dashed line. The header is outside of the scope because of

3.1.2. Controllers, models, and scope: managing data and logic

Controllers are functions that are attached to a Document Object Model (DOM) node and are used to drive the logic of your application. A controller is essentially a function object in JavaScript that can be used to communicate with the scope and respond to events.

The scope is like a shared context between the controller and view. Think of it as the connection between what happens in the controller and in the interface, and when the scope is updated in the controller it also updates in the view. You can see a diagram of how these pieces work together in figure 3.2, where the arrows indicate both the view and controller communicate using the scope as the hub.

The scope has two key roles: to store data and give access to controller methods. Data that’s stored on the scope is called the model. A model is any JavaScript value (usually an array or object, but it can be simple like a number or string) that you store on the scope, and it’s shared between the controller and views through the scope.