|
| 1 | +Angular Part 2, Getting Started With Angular |
| 2 | +============================================= |
| 3 | +The easiest way to get started with Angular is to use a <a href="http://yeoman.io/">Yeoman generator</a>. The |
| 4 | +code and doccumentation for the Angular generator can be found <a href="https://github.com/yeoman/generator-angular">Here</a>. |
| 5 | +While I usually don't reccommend using generators it is a good way to see how the |
| 6 | +moving pieces of Angular interact without having to worry about the file structure |
| 7 | +or naming conventions of the app. If you don't have npm and node installed look for |
| 8 | +instructions for your operating system <a href="http://nodejs.org/">on their website</a> |
| 9 | + |
| 10 | +The first step is to install Yeoman and the angular generator globally, along with |
| 11 | +bower and the grunt cli which are used for front end dependencies and build tools respectively: |
| 12 | +`npm install -g yo generator-angular bower grunt-cli`. Next create an empty directory and |
| 13 | +change into it. Then run `yo angular`, which will ask you a series of questions. |
| 14 | +When first starting out I would answer no to using sass/compass unless you already |
| 15 | +have it installed and have used it before. Answer no the bootstrap, primarily because |
| 16 | +Angular already adds a lot of classes and html bits and having the bootstrap classes |
| 17 | +in there as well will only make it more difficult to learn. The last question |
| 18 | +asks what other angular parts should be installed, get rid of everything except routes. |
| 19 | + |
| 20 | +The generator will then create a full working Angular app. To run the app, use the command |
| 21 | +`grunt serve` which will build all of the assets, start the app and if possible will open the |
| 22 | +index page in your browser. |
| 23 | + |
| 24 | +There are three major moving parts to pay attention to in this generated app. First, |
| 25 | +there's the app, located in app/scripts/app.js. This file contains the base level app |
| 26 | +and the routing information using $routeProvider. Each .when statement contains the |
| 27 | +url to watch for, and the view and controller to render when a user navigates to that |
| 28 | +url. The next parts to look for are the views and controllers. The view are located |
| 29 | +app/views and the controllers are located in app/controllers. To create a new view use the |
| 30 | +command `yo angular:view <name of your view>` this will create a .html file in app/views |
| 31 | +with the specified name. To create a new controller just use `yo angular:controller <name of controller>`. |
| 32 | +This will create a basic controller in app/controllers with the specified name. |
| 33 | + |
| 34 | +These are the minimum three pieces needed to create a single page web application. A router, some views |
| 35 | +and some controllers. Angular doesn't have a specific model construct as it just uses |
| 36 | +plain old javascript objects. Beyond these basics Anuglar has a host of features |
| 37 | +designed to increase the modularity and reusability of your code. The most important |
| 38 | +of these features include filters for transforming data or information in views (such as displaying 5.2 as $5.20). |
| 39 | +There are services for performing tasks across controllers, views and any other place that |
| 40 | +needs some reusable code. Finally, there are directives, which allow programmers to write portable |
| 41 | +code that interacts directly with the DOM. Documentation on each of these mentioned |
| 42 | +pieces of code can be found at the <a href="https://angularjs.org/">official Angular website</a> |
| 43 | +and there are Yeoman generators for each. |
| 44 | + |
| 45 | +That should get you started with Angular, obviously this doesn't inlcude everything or how |
| 46 | +to actually build full web application. Part 3 will be on how to find more information about |
| 47 | +Angular and how to stay up to date on the latest Angular trends and developments. |
| 48 | + |
0 commit comments