This application takes the developer through the process of building a web-application using Angular. The application is people directory of Web Front End Department of Asian Tech Inc.
Each tagged commit is a separate lesson teaching a single aspect of Angular.
The tutorial based on http://docs.Angularjs.org/tutorial.
- Git
- Node.js and tools (
npm
,bower
,...)
- The application filesystem layout structure is based on the app-template project.
- There is no dynamic backend (no application server) for this application. Instead we fake the application server by fetching static
.json
files. - Read the Development section at the end to familiarize yourself with running and developing an Angular application.
You can check out any point of the tutorial using
git checkout step-?
To see the changes which between any two lessons use the git diff command.
git diff step-?..step-?
- Add
ngApp
directive to bootstrap the app. - Add simple template with an expression.
- Add static
HTML
list with two people intoindex.html
. We will convert this static page into dynamic one with the help of Angular.
- Convert the static
HTML
list into dynamic one by:- creating
PeopleListCtrl
controller for the application. - extracting the data from HTML, moving it into the controller as an in-memory dataset.
- converting the static HTML document into an Angular template with the use of the
ngRepeat
directive which iterates over the dataset of people. ngRepeat
clones its contents for each instance in the dataset and renders it into the view.
- creating
- Add a search box to demonstrate how:
- the data-binding works on input fields.
- to use the
filter
filter. ngRepeat
automatically shrinks and grows the number of people in the view.
- Add
empCode
property to each person in the data model. - Add a
<select>
input to change the person list order. - Override the default order value in the controller.
- Replace the in-memory dataset with data loaded from the server (in
the form of static
people.json
file).- The
people.json
file is loaded using the$http
service.
- The
- Demonstrate the use of
services
anddependency injection
akaDI
.- The
$http
service is injected into the controller throughDI
.
- The
- Add person image and links to new pages that show the person details.
- Add CSS to style the page just a notch.
- Introduce the
$route
service which allows binding URLs for deep-linking with views:- Create
PeopleListCtrl
which governs the entire app and contains $route configuration. - Install
Angular-route
using bower and load thengRoute
module. (Be sure to runnpm install
again.) - Copy route parameters to root scope
params
property for access in sub controllers. - Replace the contents of
index.html
with thengView
directive, which will display the partial template of the current route.
- Create
- Create people list route:
- Map
/people
route toPeopleListCtrl
andview/people-list.html
. - Preserve existing
PeopleListCtrl
controller. - Move existing
.html
fromindex.html
toview/people-list.html
.
- Map
- Create person details route:
- Map
/person/<person-id>
route toPersonDetailCtrl
andview/person-detail.html
. - Create empty placeholder
PersonDetailsCtrl
controller.
- Map
- Implement
PersonDetailCtrl
controller to fetch the details for a specific person from a.json
file using$http
service. - Update the template for the person detailed view.
- Add CSS to make the person details page look "pretty".
- Replace
$http
with$resource
. - Created a custom
Person
service that represents the$resource
client.
The following docs describe how you can test and develop further this application.
The application relies upon various Node.js tools, such as Bower, Karma and Protractor. You can install these by running:
npm install
This will also run bower install
, which will download the Angular files needed for the current step of the tutorial.
Most of the scripts described below will run this automatically but it doesn't do any harm to run it whenever you like.
- Run
npm start
- Navigate your browser to
http://localhost:8000/index.html
to see the app running in your browser.
We recommend using Jasmine and Karma for your unit tests/specs, but you are free to use whatever works for you.
- Start Karma with
npm test
- A browser will start and connect to the Karma server. Chrome is the default browser, others can be captured by loading the same url as the one in Chrome or by changing the
test/karma.conf.js
file.
- A browser will start and connect to the Karma server. Chrome is the default browser, others can be captured by loading the same url as the one in Chrome or by changing the
- Karma will sit and watch your application and test JavaScript files. To run or re-run tests just change any of your these files.
We recommend using Jasmine and Protractor for end-to-end testing.
Requires a webserver that serves the application. See Running the app during development, above.
- Serve the application: run
npm start
. - In a separate console run the E2E tests:
npm run protractor
. Protractor will execute the E2E test scripts against the web application itself.- The configuration is set up to run the tests on Chrome directly. If you want to run against other browsers then you must install the WebDriver,
npm run update-webdriver
, and modify the configuration attest/protractor.conf.js
.
- The configuration is set up to run the tests on Chrome directly. If you want to run against other browsers then you must install the WebDriver,
app/ --> all of the files to be used in production
index.html --> app layout file (the main html template file of the app)
css/ --> css files
app.css --> default stylesheet
img/ --> image files
js/ --> JavaScript files
app.js --> the main application module
controllers.js --> application controllers
directives.js --> application directives
services.js --> custom Angular services
view/ --> Angular view partials (partial html templates) used by ngRoute
people.html
person.html
bower_components/ --> 3rd party js libraries, including Angular and jQuery
test/ --> test source files and libraries
karma.conf.js --> config file for running unit tests with Karma
protractor.conf.js --> config file for running e2e tests with Protractor
e2e/
scenarios.js --> end-to-end specs
unit/ --> unit level specs/tests
controllersSpec.js --> specs for controllers
directivesSpec.js --> specs for directives
servicesSpec.js --> specs for services
For more information on AngularJS please check out http://angularjs.org/
at-hungbcp/angular-app-template
: https://github.com/at-hungbcp/angular-app-templateDI
: http://docs.Angularjs.org/guide/didirective
: http://docs.Angularjs.org/guide/directivefilterFilter
: http://docs.Angularjs.org/api/ng/filter/filtergit-home
: http://git-scm.comgit-github
: http://help.github.com/set-up-git-redirectngRepeat
: http://docs.Angularjs.org/api/ng/directive/ngRepeatngView
: http://docs.Angularjs.org/api/ngRoute/directive/ngViewnode-download
: http://nodejs.org/download/$resource
: http://docs.Angularjs.org/api/ngResource/service/$resource$route
: http://docs.Angularjs.org/api/ngRoute/service/$routeprotractor
: https://github.com/Angular/protractorjasmine
: http://pivotal.github.com/jasmine/karma
: http://karma-runner.github.io