Skip to content

Commit 9854b91

Browse files
committed
Starting in on section 4.2
1 parent d27576a commit 9854b91

File tree

4 files changed

+35
-14
lines changed

4 files changed

+35
-14
lines changed

images/chapter4/android/3.png

18.2 KB
Loading

images/chapter4/ios/3.png

22.4 KB
Loading

index.html

+15-7
Original file line numberDiff line numberDiff line change
@@ -1127,27 +1127,27 @@ <h4 class="exercise-start">
11271127
<p>The animation module is a lot of fun to play with, and it’s easy to use too. All you need to do is get a reference to an element using <code>getViewById()</code>, and then call that element’s <code>animate()</code> method. You may want to take a few minutes to look through our <a href="{{site.baseurl}}/ui/animation#examples">animation samples</a> and try a few of these animations for yourself in Groceries.</p>
11281128
<p>For now, let’s move on to another commonly used NativeScript UI element: the <code>&lt;ListView&gt;</code>.</p>
11291129
<h3 id="listview">ListView</h3>
1130-
<p>Talk about what list views are.</p>
1130+
<p>The ListView element lets you show a list of things on the screen, which is exactly what you need for showing a list of groceries. Before tying the grocery list to a backend API, let&#39;s start by seeing how to show a hardcoded list of items on the screen.</p>
11311131
<h4 class="exercise-start">
1132-
<b>Exercise</b>: ???
1132+
<b>Exercise</b>: Build a list view
11331133
</h4>
11341134

1135-
<p>Open <code>app/pages/list/list.html</code> and paste in the following code:</p>
1135+
<p>Open <code>app/pages/list/list.html</code> and replace its contents with the following code:</p>
11361136
<pre><code class="lang-XML">&lt;ListView [items]=&quot;groceryList&quot; id=&quot;grocery-list&quot; class=&quot;small-spacing&quot;&gt;
11371137
&lt;template #item=&quot;item&quot;&gt;
11381138
&lt;Label [text]=&quot;item.name&quot; class=&quot;medium-spacing&quot;&gt;&lt;/Label&gt;
11391139
&lt;/template&gt;
11401140
&lt;/ListView&gt;
11411141
</code></pre>
1142-
<p>We’ll talk about the syntax in a moment, for now concentrate on the new <code>class</code> attribute. Open <code>app/app.css</code> and paste the following code at the bottom of the file:</p>
1142+
<p>We’ll talk about the new syntax in a moment, but first let’s define the class names used in the previous example. Open <code>app/app.css</code> and paste the following code at the bottom of the file, which defines a few utility class names you can use throughout your app:</p>
11431143
<pre><code class="lang-CSS">.small-spacing {
11441144
margin: 5;
11451145
}
11461146
.medium-spacing {
11471147
margin: 10;
11481148
}
11491149
</code></pre>
1150-
<p>Next, open <code>app/pages/list/list.component.ts</code> and paste in the following code:</p>
1150+
<p>Next, open <code>app/pages/list/list.component.ts</code> and replace its contents with the code below:</p>
11511151
<pre><code class="lang-TypeScript">import {Component, OnInit} from &quot;angular2/core&quot;;
11521152

11531153
@Component({
@@ -1167,8 +1167,16 @@ <h4 class="exercise-start">
11671167
</code></pre>
11681168
<div class="exercise-end"></div>
11691169

1170-
<p>Break down the new XML and TypeScript code individually.</p>
1171-
<p>This list is hardcoded which isn’t a whole lot of fun.</p>
1170+
<p>Your <code>ListPage</code> class now has a single <code>groceryList</code> property, that you fill with three objects in an <code>ngOnInit</code> handler. If you run your app and login, you should see the same list of groceries on the screen:</p>
1171+
<p><img src="images/chapter4/android/3.png" alt="List view on Android">
1172+
<img src="images/chapter4/ios/3.png" alt="List view on iOS"></p>
1173+
<p>How does this work? Let’s return to this chunk of code:</p>
1174+
<pre><code class="lang-XML">&lt;ListView [items]=&quot;groceryList&quot; id=&quot;grocery-list&quot; class=&quot;small-spacing&quot;&gt;
1175+
&lt;template #item=&quot;item&quot;&gt;
1176+
&lt;Label [text]=&quot;item.name&quot; class=&quot;medium-spacing&quot;&gt;&lt;/Label&gt;
1177+
&lt;/template&gt;
1178+
&lt;/ListView&gt;
1179+
</code></pre>
11721180
<h4 class="exercise-start">
11731181
<b>Exercise</b>: ???
11741182
</h4>

src/chapters/chapter4.md

+20-7
Original file line numberDiff line numberDiff line change
@@ -140,13 +140,13 @@ For now, let’s move on to another commonly used NativeScript UI element: the `
140140

141141
### ListView
142142

143-
Talk about what list views are.
143+
The ListView element lets you show a list of things on the screen, which is exactly what you need for showing a list of groceries. Before tying the grocery list to a backend API, let's start by seeing how to show a hardcoded list of items on the screen.
144144

145145
<h4 class="exercise-start">
146-
<b>Exercise</b>: ???
146+
<b>Exercise</b>: Build a list view
147147
</h4>
148148

149-
Open `app/pages/list/list.html` and paste in the following code:
149+
Open `app/pages/list/list.html` and replace its contents with the following code:
150150

151151
``` XML
152152
<ListView [items]="groceryList" id="grocery-list" class="small-spacing">
@@ -156,7 +156,7 @@ Open `app/pages/list/list.html` and paste in the following code:
156156
</ListView>
157157
```
158158

159-
Well talk about the syntax in a moment, for now concentrate on the new `class` attribute. Open `app/app.css` and paste the following code at the bottom of the file:
159+
Well talk about the new syntax in a moment, but first lets define the class names used in the previous example. Open `app/app.css` and paste the following code at the bottom of the file, which defines a few utility class names you can use throughout your app:
160160

161161
``` CSS
162162
.small-spacing {
@@ -167,7 +167,7 @@ We’ll talk about the syntax in a moment, for now concentrate on the new `class
167167
}
168168
```
169169
170-
Next, open `app/pages/list/list.component.ts` and paste in the following code:
170+
Next, open `app/pages/list/list.component.ts` and replace its contents with the code below:
171171
172172
``` TypeScript
173173
import {Component, OnInit} from "angular2/core";
@@ -190,9 +190,22 @@ export class ListPage implements OnInit {
190190
191191
<div class="exercise-end"></div>
192192
193-
Break down the new XML and TypeScript code individually.
193+
Your `ListPage` class now has a single `groceryList` property, that you fill with three objects in an `ngOnInit` handler. If you run your app and login, you should see the same list of groceries on the screen:
194+
195+
![List view on Android](images/chapter4/android/3.png)
196+
![List view on iOS](images/chapter4/ios/3.png)
197+
198+
How does this work? Let’s return to this chunk of code:
199+
200+
``` XML
201+
<ListView [items]="groceryList" id="grocery-list" class="small-spacing">
202+
<template #item="item">
203+
<Label [text]="item.name" class="medium-spacing"></Label>
204+
</template>
205+
</ListView>
206+
```
207+
194208
195-
This list is hardcoded which isnt a whole lot of fun.
196209
197210
<h4 class="exercise-start">
198211
<b>Exercise</b>: ???

0 commit comments

Comments
 (0)