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

docs(tutorial): update to use v1.5.x and best practices #14416

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
fixup 4
- Use `!` as hash-prefix.
  • Loading branch information
gkalpak committed May 24, 2016
commit d7be60fbfd577c1954d348bb56c2455cef98ae4d
38 changes: 27 additions & 11 deletions docs/content/tutorial/step_09.ngdoc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
In this step, you will learn how to create a layout template and how to build an application that
has multiple views by adding routing, using an Angular module called {@link ngRoute ngRoute}.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this form of the link will not format the ngRoute as code block. Is that what you want?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup 😃


* When you now navigate to `/index.html`, you are redirected to `/index.html#/phones` and the phone
* When you now navigate to `/index.html`, you are redirected to `/index.html#!/phones` and the phone
list appears in the browser.
* When you click on a phone link, the URL changes to that specific phone and the stub of a phone
detail page is displayed.
Expand Down Expand Up @@ -193,18 +193,20 @@ angular.module('phonecatApp', [
]);
```

Now we can configure the `$route` service (using it's provider) for our application. In order to be
able to quickly locate the configuration code, we put it into a separate file and used the `.config`
suffix.
Now, in addition to the core services and directives, we can also configure the `$route` service
(using it's provider) for our application. In order to be able to quickly locate the configuration
code, we put it into a separate file and used the `.config` suffix.

<br />
**`app/app.config.js`:**

```js
angular.
module('phonecatApp').
config(['$routeProvider',
function config($routeProvider) {
config(['$locationProvider', '$routeProvider',
function config($locationProvider, $routeProvider) {
$locationProvider.hashPrefix('!');

$routeProvider.
when('/phones', {
template: '<phone-list></phone-list>'
Expand All @@ -217,11 +219,25 @@ suffix.
]);
```

Using the `.config()` method, we request the `$routeProvider` to be injected into our configuration
function and use the {@link ngRoute.$routeProvider#when $routeProvider.when()} and
Using the `.config()` method, we request the necessary providers (for example the `$routeProvider`)
to be injected into our configuration function and then use their methods to specify the behavior of
the corresponding services. Here, we use the
{@link ngRoute.$routeProvider#when $routeProvider.when()} and
{@link ngRoute.$routeProvider#otherwise $routeProvider.otherwise()} methods to define our
application routes.

<div class="alert alert-success">
<p>
We also used {@ink $locationProvider#hashPrefix $locationProvider.hashPrefix()} to set the
hash-prefix to `!`. This prefix will appear in the links to our client-side routes, right after
the hash (`#`) symbol and before the actual path (e.g. `index.html#!/some/path`).
</p>
<p>
Setting a prefix is not necessary, but it is considered a good practice (for reasons that are
outside the scope of this tutorial). `!` is the most commonly used prefix.
</p>
</div>

Our routes are defined as follows:

* `when('/phones')`: Determines the view that will be shown, when the URL hash fragment is
Expand Down Expand Up @@ -345,7 +361,7 @@ various URLs and verifying that the correct view was rendered.
```js
...

it('should redirect `index.html` to `index.html#/phones', function() {
it('should redirect `index.html` to `index.html#!/phones', function() {
browser.get('index.html');
expect(browser.getLocationAbsUrl()).toBe('/phones');
});
Expand All @@ -355,7 +371,7 @@ various URLs and verifying that the correct view was rendered.
describe('View: Phone list', function() {

beforeEach(function() {
browser.get('index.html#/phones');
browser.get('index.html#!/phones');
});

...
Expand All @@ -367,7 +383,7 @@ various URLs and verifying that the correct view was rendered.
describe('View: Phone details', function() {

beforeEach(function() {
browser.get('index.html#/phones/nexus-s');
browser.get('index.html#!/phones/nexus-s');
});

it('should display placeholder page with `phoneId`', function() {
Expand Down
2 changes: 1 addition & 1 deletion docs/content/tutorial/step_10.ngdoc
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ heading on the page is "Nexus S".
describe('View: Phone detail', function() {

beforeEach(function() {
browser.get('index.html#/phones/nexus-s');
browser.get('index.html#!/phones/nexus-s');
});

it('should display the `nexus-s` page', function() {
Expand Down
4 changes: 2 additions & 2 deletions docs/content/tutorial/step_14.ngdoc
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,10 @@ order to be able to hook into it with our CSS animation code.
<ul class="phones">
<li ng-repeat="phone in $ctrl.phones | filter:$ctrl.query | orderBy:$ctrl.orderProp"
class="thumbnail phone-list-item">
<a href="#/phones/{{phone.id}}" class="thumb">
<a href="#!/phones/{{phone.id}}" class="thumb">
<img ng-src="{{phone.imageUrl}}" alt="{{phone.name}}" />
</a>
<a href="#/phones/{{phone.id}}">{{phone.name}}</a>
<a href="#!/phones/{{phone.id}}">{{phone.name}}</a>
<p>{{phone.snippet}}</p>
</li>
</ul>
Expand Down