Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit fb08285

Browse files
committed
docs(tutorial): switch from bower to npm and upgrade AngularJS to 1.7.x
Related: angular/angular-phonecat#430
1 parent 29ca533 commit fb08285

File tree

9 files changed

+119
-157
lines changed

9 files changed

+119
-157
lines changed

docs/content/tutorial/index.ngdoc

+21-18
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ The tutorial instructions, from now on, assume you are running all commands from
9999

100100
### Install Node.js
101101

102-
If you want to run the preconfigured local web server and the test tools then you will also need
103-
[Node.js v4+][node].
102+
In order to install dependencies (such as the test tools and AngularJS itself) and run the
103+
preconfigured local web server, you will also need [Node.js v4+][node].
104104

105105
You can download a Node.js installer for your operating system from https://nodejs.org/en/download/.
106106

@@ -125,22 +125,25 @@ npm --version
125125
[Node Version Manager (nvm)][nvm] or [Node Version Manager (nvm) for Windows][nvm-windows].
126126
</div>
127127

128-
Once you have Node.js installed on your machine, you can download the tool dependencies by running:
128+
By installing Node.js, you also get [npm][npm], which is a command line executable for downloading
129+
and managing Node.js packages. We use it to download the AngularJS framework as well as development
130+
and testing tools.
131+
132+
Once you have Node.js installed on your machine, you can download these dependencies by running:
129133

130134
```
131135
npm install
132136
```
133137

134-
This command reads angular-phonecat's `package.json` file and downloads the following tools into the
135-
`node_modules` directory:
138+
This command reads angular-phonecat's `package.json` file and downloads the following dependencies
139+
into the `node_modules` directory:
136140

137-
* [Bower][bower] - client-side code package manager
138141
* [Http-Server][http-server] - simple local static web server
139142
* [Karma][karma] - unit test runner
140143
* [Protractor][protractor] - end-to-end (E2E) test runner
141144

142-
Running `npm install` will also automatically use bower to download the AngularJS framework into the
143-
`app/bower_components` directory.
145+
Running `npm install` will also automatically copy the AngularJS framework and other dependencies
146+
necessary for our app to work into the `app/lib/` directory.
144147

145148
<div class="alert alert-info">
146149
Note the angular-phonecat project is setup to install and run these utilities via npm scripts.
@@ -160,23 +163,23 @@ tasks that you will need while developing:
160163

161164
### Install Helper Tools (optional)
162165

163-
The Bower, Http-Server, Karma and Protractor modules are also executables, which can be installed
164-
globally and run directly from a terminal/command prompt. You don't need to do this to follow the
165-
tutorial, but if you decide you do want to run them directly, you can install these modules globally
166-
using, `sudo npm install -g ...`.
166+
The Http-Server, Karma and Protractor modules are also executables, which can be installed globally
167+
and run directly from a terminal/command prompt. You don't need to do this to follow the tutorial,
168+
but if you decide you do want to run them directly, you can install these modules globally using,
169+
`sudo npm install --global ...`.
167170

168-
For instance, to install the Bower command line executable you would do:
171+
For instance, to install the `http-server` command line executable you would do:
169172

170173
```
171-
sudo npm install -g bower
174+
sudo npm install --global http-server
172175
```
173176

174-
_(Omit the sudo if running on Windows)_
177+
_(Omit the sudo if running on Windows.)_
175178

176-
Then you can run the bower tool directly, such as:
179+
Then you can run the `http-server` tool directly, such as:
177180

178181
```
179-
bower install
182+
http-server ./app
180183
```
181184

182185

@@ -324,13 +327,13 @@ Now that you have set up your local machine, let's get started with the tutorial
324327

325328

326329
[angular-phonecat]: https://github.com/angular/angular-phonecat
327-
[bower]: https://bower.io/
328330
[git]: https://git-scm.com/
329331
[http-server]: https://github.com/nodeapps/http-server
330332
[jdk]: https://en.wikipedia.org/wiki/Java_Development_Kit
331333
[jdk-download]: https://www.oracle.com/technetwork/java/javase/downloads/index.html
332334
[karma]: https://karma-runner.github.io/
333335
[node]: https://nodejs.org/
336+
[npm]: https://www.npmjs.com/
334337
[nvm]: https://github.com/creationix/nvm
335338
[nvm-windows]: https://github.com/coreybutler/nvm-windows
336339
[protractor]: https://github.com/angular/protractor

docs/content/tutorial/step_00.ngdoc

+6-6
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ The code contains some key AngularJS elements that we will need as we progress.
5151
<head>
5252
<meta charset="utf-8">
5353
<title>My HTML File</title>
54-
<link rel="stylesheet" href="bower_components/bootstrap/dist/css/bootstrap.css" />
55-
<script src="bower_components/angular/angular.js"></script>
54+
<link rel="stylesheet" href="lib/bootstrap/dist/css/bootstrap.css" />
55+
<script src="lib/angular/angular.js"></script>
5656
</head>
5757
<body>
5858

@@ -84,7 +84,7 @@ For more info on `ngApp`, check out the {@link ngApp API Reference}.
8484
**`angular.js` script tag:**
8585

8686
```html
87-
<script src="bower_components/angular/angular.js"></script>
87+
<script src="lib/angular/angular.js"></script>
8888
```
8989

9090
This code downloads the `angular.js` script which registers a callback that will be executed by the
@@ -154,16 +154,16 @@ and one static binding, and our model is empty. That will soon change!
154154

155155
Most of the files in your working directory come from the [angular-seed project][angular-seed],
156156
which is typically used to bootstrap new AngularJS projects. The seed project is pre-configured to
157-
install the AngularJS framework (via `bower` into the `app/bower_components/` directory) and tools
158-
for developing and testing a typical web application (via `npm`).
157+
install the AngularJS framework (via `npm` into the `app/lib/` directory) and tools for developing
158+
and testing a typical web application (via `npm`).
159159

160160
For the purposes of this tutorial, we modified the angular-seed with the following changes:
161161

162162
* Removed the example app.
163163
* Removed unused dependencies.
164164
* Added phone images to `app/img/phones/`.
165165
* Added phone data files (JSON) to `app/phones/`.
166-
* Added a dependency on [Bootstrap][bootstrap-3.3] in the `bower.json` file.
166+
* Added a dependency on [Bootstrap][bootstrap-3.3] in the `package.json` file.
167167

168168

169169
## Experiments

docs/content/tutorial/step_02.ngdoc

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ The view is constructed by AngularJS from this template.
3333
<html ng-app="phonecatApp">
3434
<head>
3535
...
36-
<script src="bower_components/angular/angular.js"></script>
36+
<script src="lib/angular/angular.js"></script>
3737
<script src="app.js"></script>
3838
</head>
3939
<body ng-controller="PhoneListController">
@@ -317,7 +317,7 @@ by utilizing components.
317317
<ul doc-tutorial-nav="2"></ul>
318318

319319

320-
[jasmine-docs]: https://jasmine.github.io/2.4/introduction.html
320+
[jasmine-docs]: https://jasmine.github.io/api/3.3/global
321321
[jasmine-home]: https://jasmine.github.io/
322322
[karma]: https://karma-runner.github.io/
323323
[mvc-pattern]: https://en.wikipedia.org/wiki/Model–View–Controller

docs/content/tutorial/step_03.ngdoc

+1-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ acquired skill.
120120
<html ng-app="phonecatApp">
121121
<head>
122122
...
123-
<script src="bower_components/angular/angular.js"></script>
123+
<script src="lib/angular/angular.js"></script>
124124
<script src="app.js"></script>
125125
<script src="phone-list.component.js"></script>
126126
</head>

docs/content/tutorial/step_07.ngdoc

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99
Enough of building an app with three phones in a hard-coded dataset! Let's fetch a larger dataset
1010
from our server using one of AngularJS's built-in {@link guide/services services} called
11-
{@link ng.$http $http}. We will use AngularJS's {@link guide/di dependency injection (DI)} to provide
12-
the service to the `phoneList` component's controller.
11+
{@link ng.$http $http}. We will use AngularJS's {@link guide/di dependency injection (DI)} to
12+
provide the service to the `phoneList` component's controller.
1313

1414
* There is now a list of 20 phones, loaded from the server.
1515

docs/content/tutorial/step_08.ngdoc

+5-4
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ URLs point to the `app/img/phones/` directory.
4747
...
4848
<ul class="phones">
4949
<li ng-repeat="phone in $ctrl.phones | filter:$ctrl.query | orderBy:$ctrl.orderProp" class="thumbnail">
50-
<a href="#/phones/{{phone.id}}" class="thumb">
50+
<a href="#!/phones/{{phone.id}}" class="thumb">
5151
<img ng-src="{{phone.imageUrl}}" alt="{{phone.name}}" />
5252
</a>
53-
<a href="#/phones/{{phone.id}}">{{phone.name}}</a>
53+
<a href="#!/phones/{{phone.id}}">{{phone.name}}</a>
5454
<p>{{phone.snippet}}</p>
5555
</li>
5656
</ul>
@@ -110,8 +110,9 @@ You can now rerun `npm run protractor` to see the tests run.
110110

111111
## Summary
112112

113-
Now that you have added phone images and links, go to {@link step_09 step 9} to learn about AngularJS
114-
layout templates and how AngularJS makes it easy to create applications that have multiple views.
113+
Now that you have added phone images and links, go to {@link step_09 step 9} to learn about
114+
AngularJS layout templates and how AngularJS makes it easy to create applications that have
115+
multiple views.
115116

116117

117118
<ul doc-tutorial-nav="8"></ul>

docs/content/tutorial/step_09.ngdoc

+38-49
Original file line numberDiff line numberDiff line change
@@ -23,49 +23,33 @@ has multiple views by adding routing, using an AngularJS module called {@link ng
2323
The routing functionality added in this step is provided by AngularJS in the `ngRoute` module, which
2424
is distributed separately from the core AngularJS framework.
2525

26-
Since we are using [Bower][bower] to install client-side dependencies, this step updates the
27-
`bower.json` configuration file to include the new dependency:
26+
Since we are using [npm][npm] to install client-side dependencies, this step updates the
27+
`package.json` configuration file to include the new dependency:
2828

2929
<br />
30-
**`bower.json`:**
30+
**`package.json`:**
3131

3232
```json
3333
{
3434
"name": "angular-phonecat",
35-
"description": "A starter project for AngularJS",
36-
"version": "0.0.0",
37-
"homepage": "https://github.com/angular/angular-phonecat",
38-
"license": "MIT",
39-
"private": true,
35+
...
4036
"dependencies": {
41-
"angular": "1.5.x",
42-
"angular-mocks": "1.5.x",
43-
"angular-route": "1.5.x",
37+
"angular": "1.7.x",
38+
"angular-route": "1.7.x",
4439
"bootstrap": "3.3.x"
45-
}
40+
},
41+
...
4642
}
4743
```
4844

49-
The new dependency `"angular-route": "1.5.x"` tells bower to install a version of the angular-route
50-
module that is compatible with version 1.5.x of AngularJS. We must tell bower to download and install
45+
The new dependency `"angular-route": "1.7.x"` tells npm to install a version of the angular-route
46+
module that is compatible with version 1.7.x of AngularJS. We must tell npm to download and install
5147
this dependency.
5248

5349
```
5450
npm install
5551
```
5652

57-
<div class="alert alert-info">
58-
**Note:** If you have bower installed globally, you can run `bower install`, but for this project
59-
we have preconfigured `npm install` to run bower for us.
60-
</div>
61-
62-
<div class="alert alert-warning">
63-
**Warning:** If a new version of AngularJS has been released since you last ran `npm install`, then
64-
you may have a problem with the `bower install` due to a conflict between the versions of
65-
angular.js that need to be installed. If you run into this issue, simply delete your
66-
`app/bower_components` directory and then run `npm install`.
67-
</div>
68-
6953

7054
## Multiple Views, Routing and Layout Templates
7155

@@ -127,8 +111,8 @@ service, the `$routeProvider` exposes APIs that allow you to define routes for y
127111
</div>
128112

129113
AngularJS modules solve the problem of removing global variables from the application and provide a
130-
way of configuring the injector. As opposed to AMD or require.js modules, AngularJS modules don't try
131-
to solve the problem of script load ordering or lazy script fetching. These goals are totally
114+
way of configuring the injector. As opposed to AMD or require.js modules, AngularJS modules don't
115+
try to solve the problem of script load ordering or lazy script fetching. These goals are totally
132116
independent and both module systems can live side-by-side and fulfill their goals.
133117

134118
To deepen your understanding on AngularJS's DI, see [Understanding Dependency Injection][wiki-di].
@@ -146,8 +130,8 @@ into the layout template. This makes it a perfect fit for our `index.html` templ
146130
```html
147131
<head>
148132
...
149-
<script src="bower_components/angular/angular.js"></script>
150-
<script src="bower_components/angular-route/angular-route.js"></script>
133+
<script src="lib/angular/angular.js"></script>
134+
<script src="lib/angular-route/angular-route.js"></script>
151135
<script src="app.module.js"></script>
152136
<script src="app.config.js"></script>
153137
...
@@ -203,10 +187,8 @@ code, we put it into a separate file and used the `.config` suffix.
203187
```js
204188
angular.
205189
module('phonecatApp').
206-
config(['$locationProvider', '$routeProvider',
207-
function config($locationProvider, $routeProvider) {
208-
$locationProvider.hashPrefix('!');
209-
190+
config(['$routeProvider',
191+
function config($routeProvider) {
210192
$routeProvider.
211193
when('/phones', {
212194
template: '<phone-list></phone-list>'
@@ -226,18 +208,6 @@ the corresponding services. Here, we use the
226208
{@link ngRoute.$routeProvider#otherwise $routeProvider.otherwise()} methods to define our
227209
application routes.
228210

229-
<div class="alert alert-success">
230-
<p>
231-
We also used {@link $locationProvider#hashPrefix $locationProvider.hashPrefix()} to set the
232-
hash-prefix to `!`. This prefix will appear in the links to our client-side routes, right after
233-
the hash (`#`) symbol and before the actual path (e.g. `index.html#!/some/path`).
234-
</p>
235-
<p>
236-
Setting a prefix is not necessary, but it is considered a good practice (for reasons that are
237-
outside the scope of this tutorial). `!` is the most commonly used prefix.
238-
</p>
239-
</div>
240-
241211
Our routes are defined as follows:
242212

243213
* `when('/phones')`: Determines the view that will be shown, when the URL hash fragment is
@@ -261,6 +231,25 @@ the route declaration — `'/phones/:phoneId'` — as a template that is matched
261231
URL. All variables defined with the `:` prefix are extracted into the (injectable)
262232
{@link ngRoute.$routeParams $routeParams} object.
263233

234+
<div class="alert alert-info">
235+
<p>
236+
You may have noticed, that &mdash; while the configured route paths start with `/` (e.g.
237+
`/phones`) &mdash; the URLs used in templates start with `#!/` (e.g. `#!/phones`).
238+
</p>
239+
<p>
240+
Without getting into much detail, AngularJS (by default) uses the hash part of the URL (i.e.
241+
what comes after the hash (`#`) symbol) to determine the current route. In addition to that, you
242+
can also specify a {@link $locationProvider#hashPrefix hash-prefix} (`!` by default) that needs
243+
to appear after the hash symbol in order for AngularJS to consider the value an "AngularJS path"
244+
and process it (for example, try to match it to a route).
245+
</p>
246+
<p>
247+
You can find out more about how all this works in the [Using $location](guide/$location) section
248+
of the Developer Guide. But all you need to know for now, is that the URLs to our various routes
249+
should be prefixed with `#!`.
250+
</p>
251+
</div>
252+
264253

265254
## The `phoneDetail` Component
266255

@@ -345,8 +334,8 @@ any modification.
345334

346335
```js
347336
files: [
348-
'bower_components/angular/angular.js',
349-
'bower_components/angular-route/angular-route.js',
337+
'lib/angular/angular.js',
338+
'lib/angular-route/angular-route.js',
350339
...
351340
],
352341
```
@@ -424,6 +413,6 @@ With the routing set up and the phone list view implemented, we are ready to go
424413
<ul doc-tutorial-nav="9"></ul>
425414

426415

427-
[bower]: https://bower.io/
428416
[deep-linking]: https://en.wikipedia.org/wiki/Deep_linking
417+
[npm]: https://www.npmjs.com/
429418
[wiki-di]: https://github.com/angular/angular.js/wiki/Understanding-Dependency-Injection

0 commit comments

Comments
 (0)