@@ -23,49 +23,33 @@ has multiple views by adding routing, using an AngularJS module called {@link ng
23
23
The routing functionality added in this step is provided by AngularJS in the `ngRoute` module, which
24
24
is distributed separately from the core AngularJS framework.
25
25
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:
28
28
29
29
<br />
30
- **`bower .json`:**
30
+ **`package .json`:**
31
31
32
32
```json
33
33
{
34
34
"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
+ ...
40
36
"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",
44
39
"bootstrap": "3.3.x"
45
- }
40
+ },
41
+ ...
46
42
}
47
43
```
48
44
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
51
47
this dependency.
52
48
53
49
```
54
50
npm install
55
51
```
56
52
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
-
69
53
70
54
## Multiple Views, Routing and Layout Templates
71
55
@@ -127,8 +111,8 @@ service, the `$routeProvider` exposes APIs that allow you to define routes for y
127
111
</div>
128
112
129
113
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
132
116
independent and both module systems can live side-by-side and fulfill their goals.
133
117
134
118
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
146
130
```html
147
131
<head>
148
132
...
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>
151
135
<script src="app.module.js"></script>
152
136
<script src="app.config.js"></script>
153
137
...
@@ -203,10 +187,8 @@ code, we put it into a separate file and used the `.config` suffix.
203
187
```js
204
188
angular.
205
189
module('phonecatApp').
206
- config(['$locationProvider', '$routeProvider',
207
- function config($locationProvider, $routeProvider) {
208
- $locationProvider.hashPrefix('!');
209
-
190
+ config(['$routeProvider',
191
+ function config($routeProvider) {
210
192
$routeProvider.
211
193
when('/phones', {
212
194
template: '<phone-list></phone-list>'
@@ -226,18 +208,6 @@ the corresponding services. Here, we use the
226
208
{@link ngRoute.$routeProvider#otherwise $routeProvider.otherwise()} methods to define our
227
209
application routes.
228
210
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
-
241
211
Our routes are defined as follows:
242
212
243
213
* `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
261
231
URL. All variables defined with the `:` prefix are extracted into the (injectable)
262
232
{@link ngRoute.$routeParams $routeParams} object.
263
233
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
+
264
253
265
254
## The `phoneDetail` Component
266
255
@@ -345,8 +334,8 @@ any modification.
345
334
346
335
```js
347
336
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',
350
339
...
351
340
],
352
341
```
@@ -424,6 +413,6 @@ With the routing set up and the phone list view implemented, we are ready to go
424
413
<ul doc-tutorial-nav="9"></ul>
425
414
426
415
427
- [bower]: https://bower.io/
428
416
[deep-linking]: https://en.wikipedia.org/wiki/Deep_linking
417
+ [npm]: https://www.npmjs.com/
429
418
[wiki-di]: https://github.com/angular/angular.js/wiki/Understanding-Dependency-Injection
0 commit comments