forked from angular/code.angularjs.org
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstep_06.html
78 lines (63 loc) · 3.95 KB
/
step_06.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<h1>Tutorial: 6 - Templating Links & Images</h1>
<div class="tutorial-6-templating-links-images"><ul doc:tutorial-nav="6"></ul>
<p>In this step, you will add thumbnail images for the phones in the phone list, and links that, for
now, will go nowhere. In subsequent steps you will use the links to display additional information
about the phones in the catalog.</p><doc:tutorial-instructions step="6"></doc:tutorial-instructions><p>You should now see links and images of the phones in the list.</p>
<p>The most important changes are listed below. You can see the full diff on <a href="https://github.com/angular/angular-phonecat/compare/step-5...step-6">GitHub</a>:</p>
<h3>Data</h3>
<p>Note that the <code>phones.json</code> file contains unique ids and image urls for each of the phones. The
urls point to the <code>app/img/phones/</code> directory.</p>
<p><strong><code>app/phones/phones.json</code></strong> (sample snippet):</p><div ng:non-bindable><pre class="brush: js;">
[
{
...
"id": "motorola-defy-with-motoblur",
"imageUrl": "img/phones/motorola-defy-with-motoblur.0.jpg",
"name": "Motorola DEFY\u2122 with MOTOBLUR\u2122",
...
},
...
]
</pre></div><h3>Template</h3>
<p><strong><code>app/index.html</code>:</strong></p><div ng:non-bindable><pre class="brush: js; html-script: true;">
...
<ul class="phones">
<li ng:repeat="phone in phones.$filter(query).$orderBy(orderProp)">
<a href="#/phones/{{phone.id}}">{{phone.name}}</a>
<a href="#/phones/{{phone.id}}" class="thumb"><img ng:src="{{phone.imageUrl}}"></a>
<p>{{phone.snippet}}</p>
</li>
</ul>
...
</pre></div><p>To dynamically generate links that will in the future lead to phone detail pages, we used the
now-familiar <a href="#!/guide/dev_guide.compiler.markup">double-curly brace markup</a> in the <code>href</code>
attribute values. In step 2, we added the <code>{{phone.name}}</code> binding as the element content. In this
step the <code>{{phone.id}}</code> binding is used in the element attribute.</p>
<p>We also added phone images next to each record using an image tag with the <a href="#!/api/angular.directive.ng:src"><code>ng:src</code></a> directive. That directive prevents the browser from treating
the angular <code>{{ expression }}</code> markup literally, which it would have done if we had only specified
an attribute binding in a regular <code>src</code> attribute (<code><img src="{{phone.imageUrl}}"></code>). Using
<code>ng:src</code> prevents the browser from making an http request to an invalid location.</p>
<h3>Test</h3>
<p><strong><code>test/e2e/scenarios.js</code></strong>:</p><div ng:non-bindable><pre class="brush: js;">
...
it('should render phone specific links', function() {
input('query').enter('nexus');
element('.phones li a').click();
expect(browser().location().hash()).toBe('/phones/nexus-s');
});
...
</pre></div><p>We added a new end-to-end test to verify that the app is generating correct links to the phone
views that we will implement in the upcoming steps.</p>
<p>You can now refresh the browser tab with the end-to-end test runner to see the tests run, or you
can see them running on <a href="http://angular.github.com/angular-phonecat/step-6/test/e2e/runner.html">angular's server</a>.</p>
<h2>Experiments</h2>
<ul>
<li>Replace the <code>ng:src</code> directive with a plain old <code><src></code> attribute. Using tools such as Firebug,
or Chrome's Web Inspector, or inspecting the webserver access logs, confirm that the app is indeed
making an extraneous request to <code>/app/%7B%7Bphone.imageUrl%7D%7D</code> (or
<code>/app/index.html/{{phone.imageUrl}}</code>).</li>
</ul>
<h2>Summary</h2>
<p>Now that you have added phone images and links, go to <a href="#!/tutorial/step_07">step 7</a> to learn about angular
layout templates and how angular makes it easy to create applications that have multiple views.</p>
<ul doc:tutorial-nav="6"></ul></div>