Google+

Monday, January 19, 2015

#1 - First AngularJS Application For Beginners in 10 minutes

In this article we describe Step by Step How to create a First AngularJS Application For Beginners in 10 minutes,  with a very simple AngularJS setup and introducing AngularJS Expressions and Filters .
This is the Part #1 of the "AngularJS: From 0 To 100" series designed for absolute Beginners.
For this tutorial we'll make use of the open-source Brackets Web Editor, which is lightweight, powerful and very AngularJS friendly. The Brackets installation is explained in this post.
Our AngularJS App will look like this:

First AngularJS Application For Beginners in 10 minutes



First AngularJS Application For Beginners in 10 minutes




The simple AngularJS App that we're building here will look as follows:
First AngularJS Application For Beginners in 10 minutes 1

First thing we need to do is to get the AngularJS framework. But instead of downloading it to our machine, we'll load the script using CDN (Content Delivery Network) . Browse to the official AngularJS web site :
First AngularJS Application For Beginners in 10 minutes 2

Click on the "Download" button:

First AngularJS Application For Beginners in 10 minutes 3

Here choose the latest Branch (version) "Minified" and copy the "CDN" URL: that will give us access to the latest AngularJS version at the GoogleAPIs Ajax library:

First AngularJS Application For Beginners in 10 minutes 4


Don't press the "Download" button: you don't need the AngularJS in your local machine.
Open Brackets and type the following HTML:

First AngularJS Application For Beginners in 10 minutes 6

Insert the CDN AngularJS script that you copy before, and add the AngularJS "ng-app" directive to the HTML tag:

First AngularJS Application For Beginners in 10 minutes 7

Now we'll continue building our example with some headings...

First AngularJS Application For Beginners in 10 minutes 8

...and a list of the high quality "Fragile State" discography:

First AngularJS Application For Beginners in 10 minutes 9


At the top-right Brackets menu, press the "Live Preview" icon to see the HTML in the browser:


First AngularJS Application For Beginners in 10 minutes 10

Next , we'll use some AngularJS Expressions and Filters to add the album's prices.
AngularJS Expressions is code inside double brackets {{ expression }}: take a look at the documentation in the AngularJS web site :

First AngularJS Application For Beginners in 10 minutes 11
 There is also an example there:

First AngularJS Application For Beginners in 10 minutes 12

We'll use AngularJS expressions together with Filters , so read the AngularJS Filters documentation:


In order to show the prices we'll use the Expressions and Filters as follows:

First AngularJS Application For Beginners in 10 minutes 13

This AngularJS expression tell simply that the price is "11.8" , and the Filter says that is "currency" with the type "USD$" , and that there will not be fractions, the price being therefore rounded upwards.
We'll append also expressions for the other prices, but this time , using fractions :

First AngularJS Application For Beginners in 10 minutes 14

Because you enabled the Brackets "Live Preview", every time you SAVE the HTML file, the browser is automatically refreshed:

First AngularJS Application For Beginners in 10 minutes 15

First AngularJS Application For Beginners in 10 minutes 16

And the final AngularJS View will be as follows:

First AngularJS Application For Beginners in 10 minutes 17


The full AngularJS HTML code is here , to copy-paste:

<!doctype html>
<html ng-app>
<head>
<title>
    My First AngularJS App
</title>
    <script  src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.7/angular.min.js"></script>
</head>
<body>
    <h1>Fragile State Discography</h1> 
    <h2>Neil Cowley (Zero 7) and Ben Mynott</h2>
    <ol>
        <li ><img src="Nocturnal.jpg" > 
            <span id="no-fractions">Nocturnal Beats  {{11.8 | currency:"USD$":0}}  </span>
                                                                                                         </li>
        <li ><img src="Facts.jpg" > 
            <span id="fractions">The Facts And The Dreams (2003) 
                {{12.7 | currency:"USD$"}}</span>
        </li>
        <li ><img src="Voices.jpg" > 
            <span>Voices From The Dust Bowl (2004)  {{10.4 | currency}}</span>
        </li>
        <li ><img src="Pretz.jpg" > 
            <span>Soundcastles (2006)    {{9.9 | currency | uppercase}}</span>
        </li>
     </ol>

</body>
</html>




That All!!! You have begun using the AngularJS javascript framework . In this article we learned Step by Step How to create a First AngularJS Application For Beginners in 10 minutes. 
In the next article we will learn Step by Step What are Directives in AngularJS

Happy programming.....

      by Carmel Schvartzman


                                                             NEXT LESSON >>>>


כתב: כרמל שוורצמן

No comments:

Post a Comment