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>Show an image of what this looks like first and then break down the syntax in detail.</p>
1186
+
<p>Now let’s make the add button actually work.</p>
1187
+
<h4class="exercise-start">
1188
+
<b>Exercise</b>: ???
1189
+
</h4>
1190
+
1191
+
<p>Open <code>app/pages/list/list.html</code> and give the existing <code><TextField></code> a new <code>[(ngModel)]</code> attribute so that it looks like this:</p>
1192
+
<pre><codeclass="lang-XML"><TextField id="grocery" [(ngModel)]="grocery" hint="Enter a grocery item" col="0"></TextField>
1193
+
</code></pre>
1194
+
<p>Next, give image a new tap attribute binding, so that the full <code><Image></code> looks like this:</p>
<p>Next, open <code>app/pages/list/list.component.ts</code> and add the following property to the <code>ListPage</code> class (right below <code>groceryList</code>):</p>
<p>Next, add the following two inputs to the top of the <code>list.component.ts</code> file:</p>
1201
+
<pre><codeclass="lang-TypeScript">import {TextField} from "ui/text-field";
1202
+
import {topmost} from "ui/frame";
1203
+
</code></pre>
1204
+
<p>Then, add the following <code>add()</code> function to the existing <code>ListPage</code> class:</p>
1205
+
<pre><codeclass="lang-TypeScript">add() {
1206
+
if (this.grocery.trim() === "") {
1207
+
alert("Enter a grocery item");
1208
+
return;
1209
+
}
1210
+
1211
+
// Dismiss the keyboard
1212
+
var groceryTextField = <TextField>topmost().currentPage.getViewById("grocery");
1213
+
groceryTextField.dismissSoftInput();
1214
+
1215
+
this._groceryListService.add(this.grocery)
1216
+
.subscribe(
1217
+
groceryObject => {
1218
+
this.groceryList.unshift(groceryObject);
1219
+
this.grocery = "";
1220
+
},
1221
+
() => {
1222
+
alert({
1223
+
message: "An error occurred while adding an item to your list.",
1224
+
okButtonText: "OK"
1225
+
});
1226
+
this.grocery = "";
1227
+
}
1228
+
)
1229
+
}
1230
+
</code></pre>
1231
+
<p>Finally, open <code>app/shared/grocery/grocery-list.service.ts</code> and paste the following function into the <code>GroceryService</code> class:</p>
0 commit comments