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
Copy file name to clipboardExpand all lines: index.html
+6-6Lines changed: 6 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -536,13 +536,13 @@ <h4 class="exercise-start">
536
536
<h2id="application-logic">Application Logic</h2>
537
537
<p>In this chapter you’ll learn how to add JavaScript logic to your app, how to create services that talk to backend endpoints, and how to architect an app that uses multiple pages. There’s a lot to cover, so let’s start by discussing how to handle events and data binding.</p>
538
538
<h3id="events">Events</h3>
539
-
<p>Most user interfaces are driven by events. In NativeScript apps, those events are usually some user action, such as tapping, swiping, or rotating—and NativeScript abstracts the iOS- and Android-specific code for handling such events into a handful of easy-to-use APIs. Let’s start with the most common event you’ll use in a NativeScript app—<code>tap</code>.</p>
539
+
<p>Most user interfaces are driven by events. In NativeScript apps, those events are usually some user action, such as tapping, swiping, or rotating—and NativeScript abstracts the iOS- and Android-specific code for handling such events into a handful of easy-to-use APIs. Let’s start with the most common event you’ll use in a NativeScript app: <code>tap</code>.</p>
540
540
<h4class="exercise-start">
541
541
<b>Exercise</b>: Add a <code>tap</code> event handler
542
542
</h4>
543
543
544
544
<p>Open <code>app/app.component.ts</code>, find the existing sign in button within your component’s <code>template</code> (<code><Button text="Sign in"></Button></code>), and replace it with the following code:</p>
<p>Next, in the same file, replace the current <code>AppComponent</code> declaration with the one shown below:</p>
548
548
<pre><codeclass="lang-JavaScript">export class AppComponent {
@@ -554,16 +554,16 @@ <h4 class="exercise-start">
554
554
<divclass="exercise-end"></div>
555
555
556
556
<p>The <code>(eventName)="functionName()"</code> syntax is part of <ahref="https://angular.io/docs/ts/latest/guide/template-syntax.html#!#event-binding">Angular 2’s event binding system</a>, which lets you bind an event that occurs on a UI element to a function in your component’s class. In this case, the <code>(tap)="signIn()"</code> syntax tells Angular to run the <code>AppComponent</code> class’s <code>signIn()</code> function whenever the user taps the sign in button.</p>
557
-
<p>To verify this binding works try tapping the sign in button in your app; you should see “hello” logged in your terminal or command prompt as such:</p>
558
-
<p><imgsrc="images/chapter3/terminal-1.png" alt="Terminal showing the word hello logged"></p>
557
+
<p>To verify this binding works tap the “Sign In” button in your app; you should see “hello” logged in your terminal or command prompt as such:</p>
558
+
<p><imgalt="Terminal showing the word hello logged" src="images/chapter3/terminal-1.png" class="plain"></p>
559
559
<blockquote>
560
560
<p><strong>TIP</strong>:</p>
561
561
<ul>
562
562
<li>In NativeScript you can find a list of events available in the appropriate UI element’s API documentation. For instance, the <ahref="http://docs.nativescript.org/ApiReference/ui/button/Button">button element’s API documentation</a> lists its <code>tap</code> event.</li>
563
563
<li>The Angular 2 docs have a helpful <ahref="https://angular.io/docs/ts/latest/guide/cheatsheet.html">cheat sheet</a> that includes the various syntaxes available when building templates. Don’t worry too much about knowing how all these work at the moment; we’ll progressively introduce the most common syntaxes in this guide.</li>
564
564
</ul>
565
565
</blockquote>
566
-
<p>With the <code>tap</code> event in place, we now have a way of tying our UI elements in our template to TypeScript code. To make a login page actually work though, we need to introduce one other way of connecting a template to code: data binding.</p>
566
+
<p>With the <code>tap</code> event in place, you now have a way of tying the UI elements in your template to your TypeScript code. To make a login page actually work though, we need to introduce one other way of connecting a template to code: data binding.</p>
567
567
<h3id="data-binding">Data Binding</h3>
568
568
<p>Angular 2 provides several ways to bind data in your TypeScript code to UI controls, and through the magic of NativeScript those same methods are available in your iOS and Android apps.</p>
569
569
<p>The first of these is a way to bind UI attributes to properties defined in your TypeScript class. Let’s look at how it works.</p>
@@ -572,7 +572,7 @@ <h4 class="exercise-start">
572
572
</h4>
573
573
574
574
<p>In <code>app/app.component.ts</code> replace the current <code>AppComponent</code> declaration with the one shown below, which adds a new <code>email</code> property, and changes the <code>signIn()</code> method to display its value:</p>
575
-
<pre><codeclass="lang-JavaScript">export class AppComponent {
575
+
<pre><codeclass="lang-TypeScript">export class AppComponent {
Copy file name to clipboardExpand all lines: src/chapters/chapter3.md
+6-6Lines changed: 6 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@ In this chapter you’ll learn how to add JavaScript logic to your app, how to c
4
4
5
5
### Events
6
6
7
-
Most user interfaces are driven by events. In NativeScript apps, those events are usually some user action, such as tapping, swiping, or rotating—and NativeScript abstracts the iOS- and Android-specific code for handling such events into a handful of easy-to-use APIs. Let’s start with the most common event you’ll use in a NativeScript app—`tap`.
7
+
Most user interfaces are driven by events. In NativeScript apps, those events are usually some user action, such as tapping, swiping, or rotating—and NativeScript abstracts the iOS- and Android-specific code for handling such events into a handful of easy-to-use APIs. Let’s start with the most common event you’ll use in a NativeScript app: `tap`.
8
8
9
9
<h4class="exercise-start">
10
10
<b>Exercise</b>: Add a `tap` event handler
@@ -13,7 +13,7 @@ Most user interfaces are driven by events. In NativeScript apps, those events ar
13
13
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:
Next, in the same file, replace the current `AppComponent` declaration with the one shown below:
@@ -30,15 +30,15 @@ export class AppComponent {
30
30
31
31
The `(eventName)="functionName()"` syntax is part of [Angular 2’s event binding system](https://angular.io/docs/ts/latest/guide/template-syntax.html#!#event-binding), which lets you bind an event that occurs on a UI element to a function in your component’s class. In this case, the `(tap)="signIn()"` syntax tells Angular to run the `AppComponent` class’s `signIn()` function whenever the user taps the sign in button.
32
32
33
-
To verify this binding works try tapping the sign in button in your app; you should see “hello” logged in your terminal or command prompt as such:
33
+
To verify this binding works tap the “Sign In” button in your app; you should see “hello” logged in your terminal or command prompt as such:
34
34
35
-

35
+
<imgalt="Terminal showing the word hello logged"src="images/chapter3/terminal-1.png"class="plain">
36
36
37
37
> **TIP**:
38
38
> * In NativeScript you can find a list of events available in the appropriate UI element’s API documentation. For instance, the [button element’s API documentation](http://docs.nativescript.org/ApiReference/ui/button/Button) lists its `tap` event.
39
39
> * The Angular 2 docs have a helpful [cheat sheet](https://angular.io/docs/ts/latest/guide/cheatsheet.html) that includes the various syntaxes available when building templates. Don’t worry too much about knowing how all these work at the moment; we’ll progressively introduce the most common syntaxes in this guide.
40
40
41
-
With the `tap` event in place, we now have a way of tying our UI elements in our template to TypeScript code. To make a login page actually work though, we need to introduce one other way of connecting a template to code: data binding.
41
+
With the `tap` event in place, you now have a way of tying the UI elements in your template to your TypeScript code. To make a login page actually work though, we need to introduce one other way of connecting a template to code: data binding.
42
42
43
43
### Data Binding
44
44
@@ -52,7 +52,7 @@ The first of these is a way to bind UI attributes to properties defined in your
52
52
53
53
In `app/app.component.ts` replace the current `AppComponent` declaration with the one shown below, which adds a new `email` property, and changes the `signIn()` method to display its value:
0 commit comments