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

Using ng-bind instead of ng-cloak


The ng-cloak directive is a workable solution to the rendering latency problem, but to the seasoned developer, blanking out the entire page or sprinkling ng-cloak throughout the application's templates seems like a suboptimal solution. In many scenarios, a more elegant fix would be to display as much of the page as possible and interpolate data as it is calculated to make the page load seem snappier to the end user.

How to do it…

The {{ }} interpolation syntax in AngularJS causes problems when the template loads, and is displayed before compilation can occur. The following is an example:

<div ng-controller="PlayerCtrl">
  Player: <span>{{ player.name }}</span>
</div>

If this template is displayed before compilation, it will suffer from the uncompiled template flash problem and display Player: {{ player.name }} momentarily.

The ng-cloak fix is as follows:

<div ng-cloak ng-controller="PlayerCtrl">
  Player: <span>{{ player.name...