Book Image

AngularJS Directives Cookbook

Book Image

AngularJS Directives Cookbook

Overview of this book

AngularJS directives are at the center of what makes it such an exciting – and important - web development framework. With directives, you can take greater control over HTML elements on your web pages – they ‘direct’ Angular’s HTML compiler to behave in the way you want it to. It makes building modern web applications a much more expressive experience, and allows you to focus more closely on improving the way that user interaction impacts the DOM and the way your app manages data. If you’re already using Angular, you probably recognize the power of directives to transform the way you understand and build your projects – but customizing and creating your own directives to harness AngularJS to its full potential can be more challenging. This cookbook shows you how to do just that – it’s a valuable resource that demonstrates how to use directives at every stage in the workflow. Packed with an extensive range of solutions and tips that AngularJS developers shouldn’t do without, you’ll find out how to make the most of directives. You’ll find recipes demonstrating how to build a number of different user interface components with directives, so you can take complete control over how users interact with your application. You’ll also learn how directives can simplify the way you work by creating reusable directives – by customizing them with Yeoman you can be confident that you’re application has the robust architecture that forms the bedrock of the best user experiences. You’ll also find recipes that will help you learn how to unit test directives, so you can be confident in the reliability and performance of your application. Whether you’re looking for guidance to dive deeper into AngularJS directives, or you want a reliable resource, relevant to today’s web development challenges, AngularJS Directives Cookbook delivers everything you need in an easily accessible way.
Table of Contents (16 chapters)
AngularJS Directives Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Building a navbar directive


One of the interface components most commonly used on websites and web applications are navigation menus. Although they are very simple, they are also very useful in any type of application.

Getting ready

Let's build the basis for an AngularJS application. As we mentioned before, we use the Yeoman generator: generator-angm.

Tip

You must have Node.js, Yeoman, Bower, and Grunt already installed on your machine.

Open your Terminal window and type the following commands in the order they appear:

  1. To install the generator, use the following command:

    npm install generator-angm -g
    
  2. To create the application, use the following command:

    yo angm
    
  3. To create the modules, use the following command:

    yo angm:angm-module
    
  4. Use the name about for the module name.

    Repeat the last step to create the following modules: news, company, and navbar. We will discuss this in detail later.

  5. Now, test the boilerplate code. On your Terminal, type the following command:

    grunt dev
    

All the code will be compiled...