• This repository has been archived on 13/Apr/2022
  • Stars
    star
    3,128
  • Rank 14,371 (Top 0.3 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 13 years ago
  • Updated about 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Tutorial on building an angular application.

AngularJS Phone Catalog Tutorial Application

Overview

This application takes the developer through the process of building a web-application using AngularJS. The application is loosely based on the Google Phone Gallery, which no longer exists. Here is a historical reference: Google Phone Gallery on WayBack

Each tagged commit is a separate lesson teaching a single aspect of the framework.

The full tutorial can be found at https://docs.angularjs.org/tutorial.

Prerequisites

Git

  • A good place to learn about setting up git is here.
  • You can find documentation and download git here.

Node.js and Tools

  • Get Node.js.
  • Install the tool dependencies: npm install

Workings of the Application

  • The application filesystem layout structure is based on the angular-seed 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 AngularJS application.

Commits / Tutorial Outline

You can check out any point of the tutorial using:

git checkout step-?

To see the changes made between any two lessons use the git diff command:

git diff step-?..step-?

step-0 Bootstrapping

  • Add the 'angular.js' script.
  • Add the ngApp directive to bootstrap the application.
  • Add a simple template with an expression.

step-1 Static Template

  • Add a stylesheet file ('app/app.css').
  • Add a static list with two phones.

step-2 AngularJS Templates

  • Convert the static phone list to dynamic by:
    • Creating a PhoneListController controller.
    • Extracting the data from HTML into the controller as an in-memory dataset.
    • Converting the static document into a template with the use of the ngRepeat directive.
  • Add a simple unit test for the PhoneListController controller to show how to write tests and run them using Karma.

step-3 Components

  • Introduce components.
  • Combine the controller and the template into a reusable, isolated phoneList component.
  • Refactor the application and tests to use the phoneList component.

step-4 Directory and File Organization

  • Refactor the layout of files and directories, applying best practices and techniques that will make the application easier to maintain and expand in the future:
    • Put each entity in its own file.
    • Organize code by feature area (instead of by function).
    • Split code into modules that other modules can depend on.
    • Use external templates in .html files (instead of inline HTML strings).

step-5 Filtering Repeaters

  • Add a search box to demonstrate:
    • How the data-binding works on input fields.
    • How to use the filter filter.
    • How ngRepeat automatically shrinks and grows the number of phones in the view.
  • Add an end-to-end test to:
    • Show how end-to-end tests are written and used.
    • Prove that the search box and the repeater are correctly wired together.

step-6 Two-way Data Binding

  • Add an age property to the phone model.
  • Add a drop-down menu to control the phone list order.
  • Override the default order value in controller.
  • Add unit and end-to-end tests for this feature.

step-7 XHR & Dependency Injection

  • Replace the in-memory dataset with data loaded from the server (in the form of a static 'phone.json' file to keep the tutorial backend agnostic):
    • The JSON data is loaded using the $http service.
  • Demonstrate the use of services and dependency injection (DI):
    • $http is injected into the controller through DI.
    • Introduce DI annotation methods: .$inject and inline array

step-8 Templating Links & Images

  • Add a phone image and links to phone pages.
  • Add an end-to-end test that verifies the phone links.
  • Tweak the CSS to style the page just a notch.

step-9 Routing & Multiple Views

  • Introduce the $route service, which allows binding URLs to views for routing and deep-linking:
    • Add the ngRoute module as a dependency.
    • Configure routes for the application.
    • Use the ngView directive in 'index.html'.
  • Create a phone list route (/phones):
    • Map /phones to the existing phoneList component.
  • Create a phone detail route (/phones/:phoneId):
    • Map /phones/:phoneId to a new phoneDetail component.
    • Create a dummy phoneDetail component, which displays the selected phone ID.
    • Pass the phoneId parameter to the component's controller via $routeParams.

step-10 More Templating

  • Implement fetching data for the selected phone and rendering to the view:
    • Use $http in PhoneDetailController to fetch the phone details from a JSON file.
    • Create the template for the detail view.
  • Add CSS styles to make the phone detail page look "pretty-ish".

step-11 Custom Filters

  • Implement a custom checkmark filter.
  • Update the phoneDetail template to use the checkmark filter.
  • Add a unit test for the checkmark filter.

step-12 Event Handlers

  • Make the thumbnail images in the phone detail view clickable:
    • Introduce a mainImageUrl property on PhoneDetailController.
    • Implement the setImage() method for changing the main image.
    • Use ngClick on the thumbnails to register a handler that changes the main image.
    • Add an end-to-end test for this feature.

step-13 REST and Custom Services

  • Replace $http with $resource.
  • Create a custom Phone service that represents the RESTful client.
  • Use a custom Jasmine equality tester in unit tests to ignore irrelevant properties.

step-14 Animations

  • Add animations to the application:
    • Animate changes to the phone list, adding, removing and reordering phones with ngRepeat.
    • Animate view transitions with ngView.
    • Animate changes to the main phone image in the phone detail view.
  • Showcase three different kinds of animations:
    • CSS transition animations.
    • CSS keyframe animations.
    • JavaScript-based animations.

Development with angular-phonecat

The following docs describe how you can test and develop this application further.

Installing Dependencies

The application relies upon various JS libraries, such as AngularJS and jQuery, and Node.js tools, such as Karma and Protractor. You can install these by running:

npm install

This will also download the AngularJS files needed for the current step of the tutorial and copy them to app/lib.

Most of the scripts described below will run this automatically but it doesn't do any harm to run it whenever you like.

Note copying the AngularJS files from node_modules to app/lib makes it easier to serve the files by a web server.

Running the Application during Development

Unit Testing

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 and Firefox are the default browsers, others can be captured by loading the same URL or by changing the karma.conf.js file.
  • Karma will sit and watch your application and test JavaScript files. To run or re-run tests just change any of your these files.

End-to-End Testing

We recommend using Protractor for end-to-end (e2e) testing.

It requires a webserver that serves the application. See the Running the Application during Development section, above.

  • Serve the application with: npm start
  • In a separate terminal/command line window run the e2e tests: npm run protractor.
  • Protractor will execute the e2e test scripts against the web application itself. The project is set up to run the tests on Chrome directly. If you want to run against other browsers, you must modify the configuration at e2e-tests/protractor-conf.js.

Note: Under the hood, Protractor uses the Selenium Standalone Server, which in turn requires the Java Development Kit (JDK) to be installed on your local machine. Check this by running java -version from the command line.

If JDK is not already installed, you can download it here.

Application Directory Layout

app/                     --> all the source code of the app (along with unit tests)
  lib/...                --> 3rd party JS/CSS libraries, including AngularJS and jQuery (copied over from `node_modules/`)
  core/                  --> all the source code of the core module (stuff used throughout the app)
    checkmark/...        --> files for the `checkmark` filter, including JS source code, specs
    phone/...            --> files for the `core.phone` submodule, including JS source code, specs
    core.module.js       --> the core module
  img/...                --> image files
  phone-detail/...       --> files for the `phoneDetail` module, including JS source code, HTML templates, specs
  phone-list/...         --> files for the `phoneList` module, including JS source code, HTML templates, specs
  phones/...             --> static JSON files with phone data (used to fake a backend API)
  app.animations.css     --> hooks for running CSS animations with `ngAnimate`
  app.animations.js      --> hooks for running JS animations with `ngAnimate`
  app.config.js          --> app-wide configuration of AngularJS services
  app.css                --> default stylesheet
  app.module.js          --> the main app module
  index.html             --> app layout file (the main HTML template file of the app)

e2e-tests/               --> config and source files for e2e tests
  protractor.conf.js     --> config file for running e2e tests with Protractor
  scenarios.js           --> e2e specs

node_modules/...         --> 3rd party libraries and development tools (fetched using `npm`)

scripts/                 --> handy scripts
  private/...            --> private scripts used by the AngularJS Team to maintain this repo
  update-repo.sh         --> script for pulling down the latest version of this repo (!!! DELETES ALL CHANGES YOU HAVE MADE !!!)

karma.conf.js            --> config file for running unit tests with Karma
package.json             --> Node.js specific metadata, including development tools dependencies
package-lock.json        --> Npm specific metadata, including versions of installed development tools dependencies

Contact

For more information on AngularJS, please check out https://angularjs.org/.

More Repositories

1

angular

Deliver web apps with confidence 🚀
TypeScript
96,000
star
2

angular.js

AngularJS - HTML enhanced for web apps!
JavaScript
59,091
star
3

angular-cli

CLI tool for Angular
TypeScript
26,756
star
4

components

Component infrastructure and Material Design components for Angular
TypeScript
24,333
star
5

material

Material design for AngularJS
JavaScript
16,637
star
6

angular-seed

Seed project for angular apps.
JavaScript
13,027
star
7

protractor

E2E test framework for Angular apps
JavaScript
8,780
star
8

angularfire

Angular + Firebase = ❤️
TypeScript
7,692
star
9

flex-layout

Provides HTML UI layout for Angular applications; using Flexbox and a Responsive API
TypeScript
5,904
star
10

universal

Server-side rendering and Prerendering for Angular
TypeScript
4,040
star
11

zone.js

Implements Zones for JavaScript
TypeScript
3,243
star
12

quickstart

Angular QuickStart - source from the documentation
JavaScript
3,128
star
13

batarang

AngularJS WebInspector Extension for Chrome
JavaScript
2,444
star
14

material-start

Starter Repository for AngularJS Material
JavaScript
2,214
star
15

universal-starter

Angular Universal starter kit by @AngularClass
TypeScript
2,028
star
16

mobile-toolkit

Tools for building progressive web apps with Angular
JavaScript
1,344
star
17

in-memory-web-api

The code for this project has moved to the angular/angular repo. This repo is now archived.
TypeScript
1,172
star
18

angular.io

Website for the Angular project (see github.com/angular/angular for the project repo)
HTML
1,032
star
19

angular2-seed

TypeScript
1,011
star
20

tsickle

Tsickle — TypeScript to Closure Translator
TypeScript
893
star
21

material.angular.io

Docs site for Angular Components
TypeScript
889
star
22

di.js

Dependency Injection Framework for the future generations...
JavaScript
822
star
23

react-native-renderer

Use Angular and React Native to build applications for Android and iOS
TypeScript
789
star
24

vscode-ng-language-service

Angular extension for Visual Studio Code
TypeScript
777
star
25

dgeni

Flexible JavaScript documentation generator used by AngularJS, Protractor and other JS projects
TypeScript
770
star
26

angular-cn

Chinese localization of angular.io
Pug
761
star
27

router

The Angular 1 Component Router
JavaScript
667
star
28

angular-electron

Angular2 + Electron
TypeScript
610
star
29

devkit

549
star
30

bower-material

This repository is used for publishing the AngularJS Material v1.x library
JavaScript
506
star
31

watchtower.js

ES6 Port of Angular.dart change detection code.
JavaScript
410
star
32

preboot

Coordinate transfer of state from server to client view for isomorphic/universal JavaScript web applications
TypeScript
384
star
33

angular-hint

run-time hinting for AngularJS applications
JavaScript
368
star
34

angular-bazel-example

MOVED to the bazel nodejs monorepo 👉
TypeScript
350
star
35

builtwith.angularjs.org

builtwith.angularjs.org
HTML
271
star
36

protractor-accessibility-plugin

Runs a set of accessibility audits
JavaScript
263
star
37

angularjs.org

code for angularjs.org site
JavaScript
260
star
38

angular-update-guide

An interactive guide to updating the version of Angular in your apps
TypeScript
251
star
39

webdriver-manager

A binary manager for E2E testing
TypeScript
225
star
40

bower-angular

Bower package for AngularJS
CSS
224
star
41

angular-ja

repository for Japanese localization of angular.io
TypeScript
212
star
42

ngSocket

WebSocket support for angular
JavaScript
204
star
43

peepcode-tunes

Peepcode's Backbone.js Music Player Reimplemented in AngularJS
JavaScript
204
star
44

clutz

Closure to TypeScript `.d.ts` generator
Java
163
star
45

benchpress

JavaScript
160
star
46

code.angularjs.org

code.angularjs.org
153
star
47

ngcc-validation

Angular Ivy library compatibility validation project
TypeScript
146
star
48

dgeni-packages

A collection of dgeni packages for generating documentation from source code.
JavaScript
143
star
49

bower-angular-route

angular-route bower repo
JavaScript
143
star
50

atscript-playground

A repo to play with AtScript.
JavaScript
141
star
51

bower-angular-animate

Bower package for the AngularJS animation module
JavaScript
137
star
52

protractor-cookbook

Examples for using Protractor in various common scenarios.
TypeScript
130
star
53

diary.js

Flexible logging and profiling library for JavaScript
JavaScript
127
star
54

bower-angular-i18n

internationalization module for AngularJS
JavaScript
125
star
55

ts-minify

A tool to aid minification of Typescript code, using Typescript's type information.
TypeScript
119
star
56

closure-demo

TypeScript
114
star
57

ngMigration-Forum

109
star
58

watScript

The next generation JavaScript language that will kill ALL the frameworks!
101
star
59

material-adaptive

Adaptive template development with Angular Material
JavaScript
101
star
60

bower-angular-sanitize

angular-sanitize bower repo
JavaScript
99
star
61

code-of-conduct

A code of conduct for all Angular projects
99
star
62

clang-format

Node repackaging of the clang-format native binary
Python
97
star
63

tactical

Data access library for Angular
TypeScript
93
star
64

bower-angular-resource

angular-resource bower repo
JavaScript
92
star
65

dashboard.angularjs.org

AngularJS Dashboard
JavaScript
89
star
66

angular-jquery-ui

jQueryUI widgets wrapped as angular widgets
JavaScript
88
star
67

bower-angular-mocks

angular-mocks.js bower repo
JavaScript
87
star
68

bower-angular-cookies

angular-cookies bower repo
JavaScript
85
star
69

issue-zero

TypeScript
82
star
70

bower-angular-touch

JavaScript
79
star
71

templating

Templating engine for Angular 2.0
JavaScript
76
star
72

a

Library for annotating ES5
JavaScript
67
star
73

material-icons

Common resources for material design in AngularJS
66
star
74

vladivostok

TypeScript
65
star
75

dev-infra

Angular Development Infrastructure
JavaScript
65
star
76

bower-angular-messages

JavaScript
63
star
77

angular-component-spec

Specification for reusable AngularJS components
61
star
78

ci.angularjs.org

ci.angularjs.org CI server scripts
Shell
60
star
79

projects

github reference application for Angular 2.0
JavaScript
58
star
80

codelabs

55
star
81

code.material.angularjs.org

Documentation site for AngularJS Material
HTML
50
star
82

material-tools

Tools for AngularJS Material
TypeScript
47
star
83

jasminewd

Adapter for Jasmine-to-WebDriverJS
JavaScript
46
star
84

material-update-tool

Standalone update tool for updating Angular CDK and Material
TypeScript
46
star
85

material-builds

Build snapshots for @angular/material
JavaScript
45
star
86

material2-docs-content

Docs content for @angular/material
HTML
39
star
87

cdk-builds

Angular CDK builds
JavaScript
38
star
88

benchpress-tree

A reference implementation of a benchpress deep-tree benchmark as seen in Angular
JavaScript
37
star
89

router-builds

@angular/router build artifacts
JavaScript
36
star
90

angular-ko

HTML
36
star
91

prophecy

Deferred/Promise for AngularJS 2.0
JavaScript
36
star
92

answers-app

TypeScript
36
star
93

assert

A runtime type assertion library.
JavaScript
35
star
94

ngo

TypeScript
34
star
95

protractor-console-plugin

Checks the browser log after each test for warnings and errors
JavaScript
34
star
96

examples

TypeScript
33
star
97

introduction-to-angular

TypeScript
33
star
98

microsites

Master repository for sites on the angular.io subdomains (universal.angular.io, material.angular.io, etc)
HTML
29
star
99

core-builds

@angular/core build artifacts
JavaScript
29
star
100

ngtools-webpack-builds

Build artifacts for @ngtools/webpack
JavaScript
28
star