You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<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 <ahref="{{site.baseurl}}/ui/animation#examples">animation samples</a> and try a few of these animations for yourself in Groceries.</p>
1128
1128
<p>For now, let’s move on to another commonly used NativeScript UI element: the <code><ListView></code>.</p>
1129
1129
<h3id="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's start by seeing how to show a hardcoded list of items on the screen.</p>
1131
1131
<h4class="exercise-start">
1132
-
<b>Exercise</b>: ???
1132
+
<b>Exercise</b>: Build a list view
1133
1133
</h4>
1134
1134
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>
<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>
1143
1143
<pre><codeclass="lang-CSS">.small-spacing {
1144
1144
margin: 5;
1145
1145
}
1146
1146
.medium-spacing {
1147
1147
margin: 10;
1148
1148
}
1149
1149
</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>
1151
1151
<pre><codeclass="lang-TypeScript">import {Component, OnInit} from "angular2/core";
<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><imgsrc="images/chapter4/android/3.png" alt="List view on Android">
1172
+
<imgsrc="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>
Copy file name to clipboardExpand all lines: src/chapters/chapter4.md
+20-7
Original file line number
Diff line number
Diff line change
@@ -140,13 +140,13 @@ For now, let’s move on to another commonly used NativeScript UI element: the `
140
140
141
141
### ListView
142
142
143
-
Talkaboutwhatlistviewsare.
143
+
TheListViewelementletsyoushowalistofthingsonthe screen, whichisexactlywhatyouneedforshowingalistofgroceries. Beforetyingthegrocerylisttoabackend API, let's start by seeing how to show a hardcoded list of items on the screen.
Next, open `app/pages/list/list.component.ts` and replace its contents with the code below:
171
171
172
172
``` TypeScript
173
173
import {Component, OnInit} from"angular2/core";
@@ -190,9 +190,22 @@ export class ListPage implements OnInit {
190
190
191
191
<div class="exercise-end"></div>
192
192
193
-
BreakdownthenewXMLandTypeScriptcodeindividually.
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
+

196
+

197
+
198
+
How does this work? Let’s return to this chunk of code:
0 commit comments