Book Image

AngularJS Web application development Cookbook

By : Matthew Frisbie
Book Image

AngularJS Web application development Cookbook

By: Matthew Frisbie

Overview of this book

Packed with easy-to-follow recipes, this practical guide will show you how to unleash the full might of the AngularJS framework. Skip straight to practical solutions and quick, functional answers to your problems without hand-holding or slogging through the basics. Avoid antipatterns and pitfalls, and squeeze the maximum amount out of the most powerful parts of the framework, from creating promise-driven applications to building an extensible event bus. Throughout, take advantage of a clear problem-solving approach that offers code samples and explanations of components you should be using in your production applications.
Table of Contents (17 chapters)
AngularJS Web Application Development Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Preface

"Make it work. Make it right. Make it fast."

Back when the world was young, Kent Beck forged this prophetic sentiment. Even today, in the ultra-modern realm of performant single-page application JavaScript frameworks, his idea still holds sway. This nine-word expression describes the general progression through which a pragmatic developer creates high-quality software.

In the process of discovering how to optimally wield a technology, a developer will execute this progression many times, and each time will be a learning experience regarding some new understanding of the technology.

This cookbook is intended to act as a companion guide through this process. The recipes in this book will intimately examine every major aspect of the framework in order to maximize your comprehension. Every time you open this book, you should gain an expanded understanding of the brilliance of the AngularJS framework.

What this book covers

Chapter 1, Maximizing AngularJS Directives, dissects the various components of directives and demonstrates how to wield them in your applications. Directives are the bread and butter of AngularJS, and the tools presented in this chapter will maximize your ability to take advantage of their extensibility.

Chapter 2, Expanding Your Toolkit with Filters and Service Types, covers two major tools for code abstraction in your application. Filters are an important pipeline between the model and its appearance in the view, and are essential tools for managing data presentation. Services act as broadly applicable houses for dependency-injectable modules and resource access.

Chapter 3, AngularJS Animations, offers a collection of recipes that demonstrate various ways to effectively incorporate animations into your application. Additionally, it will dive deep down into the internals of animations in order to give you a complete perspective on how everything really works under the hood.

Chapter 4, Sculpting and Organizing Your Application, gives you strategies for controlling the application initialization, organizing your files and modules, and managing your template delivery.

Chapter 5, Working with the Scope and Model, breaks open the various components involving ngModel and provides details of the ways in which they can integrate into your application flow.

Chapter 6, Testing in AngularJS, gives you all the pieces you need to jump into writing test-driven applications. It demonstrates how to configure a fully operational testing environment, how to organize your test files and modules, and everything involved in creating a suite of unit and E2E tests.

Chapter 7, Screaming Fast AngularJS, is a response to anyone who has ever complained about AngularJS being slow. The recipes in this chapter give you all the tools you need to tune all aspects of your application's performance and take it from a steam engine to a bullet train.

Chapter 8, Promises, breaks apart the asynchronous program flow construct, exposes its internals, then builds it all the way back up to discuss strategies for your application's integration. This chapter also demonstrates how promises can and should integrate into your application's routing and resource access utilities.

Chapter 9, What's New in AngularJS 1.3, goes through how your application can integrate the slew of new features and changes that were introduced in the AngularJS 1.3 and the later AngularJS 1.2.x releases.

Chapter 10, AngularJS Hacks, is a collection of clever and interesting strategies that you can use to stretch the boundaries of AngularJS's organization and performance.

What you need for this book

Almost every example in this book has been added to JSFiddle, with the links provided in the text. This allows you to merely visit a URL in order to test and modify the code with no setup of any kind, on any major browser and on any major operating system. If you want to replicate an example outside of JSFiddle, all the external content (AngularJS, AngularJS modules, third-party libraries and modules) is served from https://code.angularjs.org/ and https://cdnjs.com/.

Chapter 6, Testing in AngularJS, involves setting up a testing framework, which should be able to be accomplished on any major Unix-based operating system (OS X and, Linux). The test suite is built on top of Grunt, Karma, Selenium, and Protractor; all of these and their dependencies can be installed through npm.

Who this book is for

There are already plenty of introductory resources to guide a green developer into the thick of AngularJS. This cookbook is for developers with at least basic knowledge of JavaScript and AngularJS, and who are looking to expand their perspective on the framework.

The goal of this text is to have you walk away from reading about an AngularJS concept armed with a solid understanding of how it works, insight into the best ways to wield it in real-world applications, and annotated code examples to get you started.

Sections

In this book, you will find several headings that appear frequently (Getting ready, How to do it, How it works, There's more, and See also).

To give clear instructions on how to complete a recipe, we use these sections as follows:

Getting ready

This section tells you what to expect in the recipe, and describes how to set up any software or any preliminary settings required for the recipe.

How to do it…

This section contains the steps required to follow the recipe.

How it works…

This section usually consists of a detailed explanation of what happened in the previous section.

There's more…

This section consists of additional information about the recipe in order to make the reader more knowledgeable about the recipe.

See also

This section provides helpful links to other useful information for the recipe.

Conventions

In this book, you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles, and an explanation of their meaning.

Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "By cleverly using directives and the $compile service, this exact directive functionality is possible."

A block of code is set as follows:

(index.html)

<!-- specify root element of application -->
<div ng-app="myApp">
  <!-- register 'my-template.html' with $templateCache -->
  <script type="text/ng-template" id="my-template.html">
    <div ng-repeat="num in [1,2,3,4,5]">{{ num }}</div>
  </script>  
  
  <!-- your custom element -->
  <my-directive></my-directive>
</div>

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

(app.js)

.directive('iso', function () {
  return {
    scope: {}
  };
});

Any command-line input or output is written as follows:

npm install protractor grunt-protractor-runner --save-dev

New terms and important words are shown in bold. Words that you see on the screen, in menus or dialog boxes for example, appear in the text like this: "The following directive will display NW, NE, SW, or SE depending on where the cursor is relative to it."

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.

To send us general feedback, simply send an e-mail to , and mention the book title via the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide on www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files for all Packt books you have purchased from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you would report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the errata submission form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded on our website, or added to any list of existing errata, under the Errata section of that title. Any existing errata can be viewed by selecting your title from http://www.packtpub.com/support.

Piracy

Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works, in any form, on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at with a link to the suspected pirated material.

We appreciate your help in protecting our authors, and our ability to bring you valuable content.

Questions

You can contact us at if you are having a problem with any aspect of the book, and we will do our best to address it.