Skip to content

Commit 51f692a

Browse files
committed
Saving off ViewChild changes
1 parent 06a73cf commit 51f692a

File tree

6 files changed

+176
-125
lines changed

6 files changed

+176
-125
lines changed

images/chapter4/typescript.png

9.92 KB
Loading

index.html

Lines changed: 83 additions & 63 deletions
Large diffs are not rendered by default.

src/chapters/chapter2.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,9 @@ Open `app/app.component.ts` and replace the existing `@Component` with the follo
140140
@Component({
141141
selector: "my-app",
142142
template: `
143-
<TextField hint="Email Address" id="email" keyboardType="email"
143+
<TextField hint="Email Address" keyboardType="email"
144144
autocorrect="false" autocapitalizationType="none"></TextField>
145-
<TextField hint="Password" id="password" secure="true"></TextField>
145+
<TextField hint="Password" secure="true"></TextField>
146146
147147
<Button text="Sign in"></Button>
148148
<Button text="Sign up for Groceries"></Button>
@@ -199,9 +199,9 @@ Open `app/app.component.ts` and add a `<StackLayout>` element within your compon
199199
selector: "my-app",
200200
template: `
201201
<StackLayout>
202-
<TextField hint="Email Address" id="email" keyboardType="email"
202+
<TextField hint="Email Address" keyboardType="email"
203203
autocorrect="false" autocapitalizationType="none"></TextField>
204-
<TextField hint="Password" id="password" secure="true"></TextField>
204+
<TextField hint="Password" secure="true"></TextField>
205205
206206
<Button text="Sign in"></Button>
207207
<Button text="Sign up for Groceries"></Button>
@@ -308,9 +308,9 @@ Open your `app/app.component.ts` file and add a `styleUrls` property, so that th
308308
selector: "my-app",
309309
template: `
310310
<StackLayout>
311-
<TextField hint="Email Address" id="email" keyboardType="email"
311+
<TextField hint="Email Address" keyboardType="email"
312312
autocorrect="false" autocapitalizationType="none"></TextField>
313-
<TextField hint="Password" id="password" secure="true"></TextField>
313+
<TextField hint="Password" secure="true"></TextField>
314314
315315
<Button text="Sign in"></Button>
316316
<Button text="Sign up for Groceries"></Button>
@@ -338,7 +338,7 @@ Button, TextField {
338338
margin-right: 16;
339339
margin-bottom: 10;
340340
}
341-
#submit-button {
341+
.submit-button {
342342
background-color: #CB1D00;
343343
color: white;
344344
margin-top: 20;
@@ -353,21 +353,21 @@ Why three files? Much like you divided your global files into `app.css`, `platfo
353353

354354
The great thing about placing CSS rules at the component level is you can use concise CSS selectors such as `Button` and `TextField`, and not worry about those rules applying to all buttons and text fields in your application, as Angular 2 ensures those rules remain scoped to your component.
355355

356-
Before we see what your app looks like now, there’s one small change you need to make. Notice that the last selector used in `login-common.css` is `#submit-button`. Much like using CSS on the web, in NativeScript you can both `id` and `class` attributes to target specific user interface elements, but at the moment there’s no UI element in your app with an `id` of `"submit-button"`. Let’s change that.
356+
Before we see what your app looks like now, there’s one small change you need to make. Notice that the last selector used in `login-common.css` is `.submit-button`. Much like using CSS on the web, in NativeScript you can both `id` and `class` attributes to target specific user interface elements, but at the moment there’s no UI element in your app with an `class` of `"submit-button"`. Let’s change that.
357357

358358
<h4 class="exercise-start">
359-
<b>Exercise</b>: Add an `id` attribute
359+
<b>Exercise</b>: Add a `class` attribute
360360
</h4>
361361

362362
Open your `app/app.component.ts` file, find `<Button text="Sign in"></Button>` in your component’s `template`, and replace it with the code below:
363363

364364
``` XML
365-
<Button text="Sign in" id="submit-button"></Button>
365+
<Button text="Sign in" class="submit-button"></Button>
366366
```
367367

368368
<div class="exercise-end"></div>
369369

370-
With this last `id` change in place your app is starting to look a little nicer:
370+
With this last `class` change in place your app is starting to look a little nicer:
371371

372372
![login 4](images/chapter2/ios/4.png)
373373
![login 4](images/chapter2/android/4.png)

src/chapters/chapter3.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Most user interfaces are driven by events. In NativeScript apps, those events ar
1313
Open `app/app.component.ts`, find the existing sign in button within your component’s `template` (`<Button text="Sign in"></Button>`), and replace it with the following code:
1414

1515
``` TypeScript
16-
<Button text="Sign in" id="submit-button" (tap)="submit()"></Button>
16+
<Button text="Sign in" class="submit-button" (tap)="submit()"></Button>
1717
```
1818

1919
Next, in the same file, replace the current `AppComponent` declaration with the one shown below:
@@ -64,7 +64,7 @@ export class AppComponent {
6464
Next, find the first `<TextField>` in your component’s `template` and replace it with the code below, which adds a new `text` attribute:
6565

6666
``` XML
67-
<TextField hint="Email Address" id="email" keyboardType="email" [text]="email"
67+
<TextField hint="Email Address" keyboardType="email" [text]="email"
6868
autocorrect="false" autocapitalizationType="none"></TextField>
6969
```
7070

@@ -92,7 +92,7 @@ To fix this, you need to switch to Angular 2’s two-way data binding syntax.
9292
In `app/app.component.ts`, find the first `<TextField>`, and replace it with the `<TextField>` below, which introduces a new `[(ngModel)]` attribute:
9393

9494
``` XML
95-
<TextField hint="Email Address" id="email" keyboardType="email" [(ngModel)]="email"
95+
<TextField hint="Email Address" keyboardType="email" [(ngModel)]="email"
9696
autocorrect="false" autocapitalizationType="none"></TextField>
9797
```
9898

@@ -114,7 +114,7 @@ Before we move on, let’s make one additional change to show what else you can
114114
Open `app/app.component.ts` and replace the two existing buttons with the code below:
115115

116116
``` XML
117-
<Button [text]="isLoggingIn ? 'Sign in' : 'Sign up'" id="submit-button" (tap)="submit()"></Button>
117+
<Button [text]="isLoggingIn ? 'Sign in' : 'Sign up'" class="submit-button" (tap)="submit()"></Button>
118118
<Button [text]="isLoggingIn ? 'Sign up' : 'Back to login'" (tap)="toggleDisplay()"></Button>
119119
```
120120

@@ -202,9 +202,9 @@ Instead of storing data on the `AppComponent` directly, you’re now using the `
202202
Your next step is to use this new model object in your template. To do that, replace the two existing `<TextField>`s with the code shown below, which updates the `[(ngModel)]` bindings to point at the new `User` object:
203203

204204
``` XML
205-
<TextField hint="Email Address" id="email" keyboardType="email" [(ngModel)]="user.email"
205+
<TextField hint="Email Address" keyboardType="email" [(ngModel)]="user.email"
206206
autocorrect="false" autocapitalizationType="none"></TextField>
207-
<TextField hint="Password" id="password" secure="true" [(ngModel)]="user.password"></TextField>
207+
<TextField hint="Password" secure="true" [(ngModel)]="user.password"></TextField>
208208
```
209209

210210
As one final change, because this template is getting to be a bit complex, let’s move it into a separate file. Open `app/pages/login/login.html` and paste in the following code:
@@ -213,11 +213,11 @@ As one final change, because this template is getting to be a bit complex, let
213213
<StackLayout>
214214
<Image src="res://logo_login" stretch="none" horizontalAlignment="center"></Image>
215215

216-
<TextField hint="Email Address" id="email" keyboardType="email" [(ngModel)]="user.email"
216+
<TextField hint="Email Address" keyboardType="email" [(ngModel)]="user.email"
217217
autocorrect="false" autocapitalizationType="none"></TextField>
218-
<TextField hint="Password" id="password" secure="true" [(ngModel)]="user.password"></TextField>
218+
<TextField hint="Password" secure="true" [(ngModel)]="user.password"></TextField>
219219

220-
<Button [text]="isLoggingIn ? 'Sign in' : 'Sign up'" id="submit-button" (tap)="submit()"></Button>
220+
<Button [text]="isLoggingIn ? 'Sign in' : 'Sign up'" class="submit-button" (tap)="submit()"></Button>
221221
<Button [text]="isLoggingIn ? 'Sign up' : 'Back to login'" (tap)="toggleDisplay()"></Button>
222222
</StackLayout>
223223
```

0 commit comments

Comments
 (0)