zondag 3 augustus 2014

Extending HTML with AngularJS's Directives

The main thing about AngularJS is that it allows us to extend the capabilities of HTML to serve the purpose of today’s dynamic webpages. In this article, I will show you how you can use AngularJS‘s Directives to make your development faster, easier, and your code more maintainable.


Preparation


Step 1: HTML Template


To make things simpler we will write all of our code in one HTML file. Create it and put the basic HTML template in it:


<!DOCTYPE html> <html> <head> </head> <body> </body> </html>

Now add the angular.min.js file from Google’s CDN in the <head> of the document:


 <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.16/angular.min.js"></script>

Step 2: Creating the Module


Now let’s create the module for our directives. I will call it example, but you can choose whatever you want, just keep in mind that we will use this name as a namespace for the directives we create later. 


Put this code in a script tag a the bottom of the <head>: