@@ -23,49 +23,33 @@ has multiple views by adding routing, using an AngularJS module called {@link ng
2323The routing functionality added in this step is provided by AngularJS in the `ngRoute` module, which
2424is 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
5147this dependency.
5248
5349```
5450npm 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
129113AngularJS 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
132116independent and both module systems can live side-by-side and fulfill their goals.
133117
134118To 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
227209application 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-
241211Our 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
261231URL. 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 — while the configured route paths start with `/` (e.g.
237+ `/phones`) — 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