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

Creating custom AngularJS comments


An overlooked ability of AngularJS is its ability to wield directives with the intention of streamlining the development process. One awesome way to do this is by using directives to comment in your application.

How to do it…

Normally, nesting HTML comments requires variable syntax as shown here:

<!--
<div>
  <p>I am the outer comment</p>
  <!- -
    <p>I am the inner comment</p>
  - ->
</div>
-->

This is completely obnoxious. It would be much better to be able to add comments anywhere without having to worry about which comments are already in place. Since the HTML comment convention doesn't suit your needs, you are able to just make your own comment directive, as follows:

(app.js)

angular.module('myApp', [])
.directive('x', function() {
  return {
    restrict: 'AE',
    compile: function(el) {
      el.remove();
    }
  };
});

Now, you are able to do the following, using attribute comments:

(index.html)

&lt...