AngularJS Application Architecture

101 minutes

One challenge when learning AngularJS is that most examples are trivial. It is difficult to find materials on learning "real-world" patterns and practices.

The joy of Angular is that you are free to build an application in any form that you wish. MCV, MVVM, MVP, MVwhatever... You get to decide! Freedom is wonderful.

"But what if I choose poorly?"

Good question.

This series will demonstrate how to organize and tool your AngularJS application for real work. It's an opinion. A way that has worked on our own projects. Use it as a guide for building the solution that best suits the needs of your projects. All projects are different, but with the right set of modular tools you can build a foundation for success.

Building on the previous series, we are going to refactor Eggly to be modular and scalable. By introducing modules and sub-modules, domain models and state management with ui-router, we will start to establish best practices on how an AngularJS application should not only function, but fit together.

Be sure to check out Part 1: AngularJS App From Scratch: Getting Started

pro-course-rss-logo

PRO RSS Feed

AngularJS Architecture: Series Introduction

AngularJS Architecture: File Structure

P

AngularJS Architecture: Using Sub-Modules

P

AngularJS Architecture: Basic State with ui-router

P

AngularJS Architecture: Using ui-router's named views

P

AngularJS Architecture: ui-router state params for sharing information

P

AngularJS Architecture: navigating between states with ui-router

P

AngularJS Architecture: Prefer the 'controller as' syntax

P

AngularJS Architecture: Refactor to a data model

P

AngularJS Architecture: Using $http to load JSON data

P

AngularJS Architecture: Control your promises with $q

P

AngularJS Architecture: Edit and Create Bookmark States

P

AngularJS Architecture: Create Bookmark

P

AngularJS Architecture: Edit Bookmark

P

AngularJS Architecture: Delete Bookmark

P

AngularJS Architecture: Animate state transitions with ui-router

P

AngularJS Architecture: Review

P
angularjs tutorial about AngularJS Architecture: Series Introduction

AngularJS Architecture: Series Introduction

2:32 angularjs

Ready to start learning about AngularJS Application Architecture? This lesson series is for you. Let's talk about what you will learn.

angularjs tutorial about AngularJS Architecture: File Structure

AngularJS Architecture: File Structure

5:51 angularjs PRO

Let's talk about the importance of having a good file structure and how it is is very much like good code in that it is self documenting and friendly to extension. We will introduce the file structure that will serve as the foundation for the rest of the series as we refactor Eggly.

angularjs tutorial about AngularJS Architecture: Using Sub-Modules

AngularJS Architecture: Using Sub-Modules

4:22 angularjs PRO

Let's look at sub-modules as a mechanism for organizing our code into logical containers that we can then compose into our main application. Leveraging sub-modules is a powerful way to add in new functionality and features into an application while minimizing the impact that it has on the existing code base.

angularjs tutorial about AngularJS Architecture: Basic State with ui-router

AngularJS Architecture: Basic State with ui-router

5:20 angularjs PRO

We will look at ui-router and learn how we can use it to define unique states with Eggly. This will allow us to leverage the power of a state machine in our AngularJS application, which goes beyond code management and into managing the states that exist within the code.

note the route doesn't actually fire unless you navigate to index.html#/ instead of index.html (see comments)

angularjs tutorial about AngularJS Architecture: Using ui-router's named views

AngularJS Architecture: Using ui-router's named views

8:03 angularjs PRO

We'll take a deeper look at ui-router as we introduce named views into Eggly. We will take the basic state that we defined in the previous video and refactor it so that it consists of two unique views within the application.

angularjs tutorial about AngularJS Architecture: ui-router state params for sharing information

AngularJS Architecture: ui-router state params for sharing information

4:53 angularjs PRO

Let's learn how to pass information from one state to another within Eggly. We learn how to define a state so that it has parameters in its definition and then read those parameters using the $stateParams service.

angularjs tutorial about AngularJS Architecture: navigating between states with ui-router

AngularJS Architecture: navigating between states with ui-router

5:00 angularjs PRO

Now that we have ui-router states in our Angular application, we can discuss the three ways to activate a state within ui-router. We will programmatically activate a state using $state.go and capture user interactions with the ui-sref directive.

angularjs tutorial about AngularJS Architecture: Prefer the 'controller as' syntax

AngularJS Architecture: Prefer the 'controller as' syntax

5:02 angularjs PRO

As of Angular 1.2, the use of $scope injectable has been greatly reduced in favor of the "controller as syntax". We are going to take a quick look at cleaning up Eggly to follow this best practice.

angularjs tutorial about AngularJS Architecture: Refactor to a data model

AngularJS Architecture: Refactor to a data model

5:53 angularjs PRO

Let's continue to refactor Eggly by introducing a valuable concept known as model promotion. We will start to extract the categories and bookmarks collections from the MainCtrl and promote them to their respective models. We will then learn how to consume those models at the controller level to populate the view.

angularjs tutorial about AngularJS Architecture: Using $http to load JSON data

AngularJS Architecture: Using $http to load JSON data

7:21 angularjs PRO

Now let's learn how use the $http service to make requests to remote servers. In our case, we will load the data from JSON files and then make them available in our controllers. We will see a few techniques that I frequently use to make working with $http data a lot more convenient.

angularjs tutorial about AngularJS Architecture: Control your promises with $q

AngularJS Architecture: Control your promises with $q

6:26 angularjs PRO

Learn how to manually control how asynchronous requests are handled with the use of promises. Because $http is built to work with promises, we saw a foreshadow of them in the previous lesson. We will take this a step further but seeing how to manually create a promise and then resolve or reject it as we see fit.

angularjs tutorial about AngularJS Architecture: Edit and Create Bookmark States

AngularJS Architecture: Edit and Create Bookmark States

12:09 angularjs PRO

In this lesson, we continue to dig into ui-router while doing some significant refactoring to our Eggly application.

We will start out by removing MainCtrl entirely from the application as we start to move functionality to more appropriate places with the application. We will build out the edit and create sub-modules to include the states and controllers for editing and creating a bookmark. With our states defined, will leverage them to manage our view instead of the ng-if statements we were previously using. We tie it all together by using CategoriesModel to track the current category and provide functionality to the BookmarksListCtrl.

We cover a lot of material in this lesson as we start to apply the concepts covered previously to finalize functionality in the application.

angularjs tutorial about AngularJS Architecture: Create Bookmark

AngularJS Architecture: Create Bookmark

6:29 angularjs PRO

In this lesson, we will complete the functionality to create a bookmark. We start by adding a createBookmark method on the BookmarksModel and then making it available to the CreateBookmarksCtrl. From there, we flesh out the CreateBookmarksCtrl and refactor the template to use the new "Controller as" syntax.

angularjs tutorial about AngularJS Architecture: Edit Bookmark

AngularJS Architecture: Edit Bookmark

12:18 angularjs PRO

In this lesson, we are going to complete the functionality for editing a bookmark. We will start by augmenting the BookmarksModel and then updating the controller and view to utilize the new functionality. We will also update the BookmarksModel.getBookmarks to cache the bookmarks so that we are not overwriting our updates on every call.

angularjs tutorial about AngularJS Architecture: Delete Bookmark

AngularJS Architecture: Delete Bookmark

2:10 angularjs PRO

In this lesson, we are going to complete the functionality for deleting a bookmark. Deleting a bookmark is significantly easier than creating or editing a bookmark with the essence being a single method in the BookmarksModel that we make available to the controller and view.

angularjs tutorial about AngularJS Architecture: Animate state transitions with ui-router

AngularJS Architecture: Animate state transitions with ui-router

3:46 angularjs PRO

In this lesson, we are going to learn how easy it is to animate ui-router state changes using ngAnimate and about 10 lines of CSS.

angularjs tutorial about AngularJS Architecture: Review

AngularJS Architecture: Review

3:44 angularjs PRO

In this lesson, we review the high level concepts that we covered over the course of this series including file structure, sub-modules, data models, ui-router and animations.

Presented by:

Lukas Ruebbelke

Lukas Ruebbelke is a technology enthusiast and author of AngularJS in Action for Manning Publications. His favorite thing to do is get people as excited about new technology as he is. He is the co-organizer of the Arizona Software Community user group and host of multiple developer events in the Phoenix metro area.

HEY, QUICK QUESTION!
Joel's Head
Why are we asking?