Skip to content

Commit 11e7358

Browse files
committed
Starting up the service discussion
1 parent 451faf7 commit 11e7358

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

index.html

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@ <h4 class="exercise-start">
563563
<b>Exercise</b>: Add a model object
564564
</h4>
565565

566-
<p>The first thing we’ll do is add a model object to store user data. Open <code>app/user/user.service.ts</code> and paste in the following code:</p>
566+
<p>The first thing we’ll do is add a model object to store user data. Open <code>app/user/user.ts</code> and paste in the following code:</p>
567567
<pre><code class="lang-JavaScript">export class User {
568568
email: string;
569569
password: string;
@@ -622,7 +622,22 @@ <h4 class="exercise-start">
622622
</code></pre>
623623
<div class="exercise-end"></div>
624624

625+
<p>With this setup you now have a <code>User</code> class that you can share across pages in your app and even across applications. But a model object that’s four simple lines of code isn’t all that exciting. Where this approach really pays off is when you’re able to share your business logic, and the code that hits your backend systems. In Angular 2 those classes are known as services. Let’s look at them next.</p>
625626
<h3 id="services">Services</h3>
627+
<p>A login screen isn’t all that useful if it doesn’t actually log users into anything. Therefore, our next task is to take the user’s email address and password, and send them to a backend endpoint to retrieve an authentication token we’ll use later in this guide. We’ll build this functionality as an Angular 2 service.</p>
628+
<p>For the purposes of this tutorial we prebuilt a handful of backend endpoints using <a href="http://www.telerik.com/platform/backend-services">Telerik Backend Services</a>, and we’ll be using those endpoints to make this app functional. Let’s see how they work.</p>
629+
<blockquote>
630+
<p><strong>NOTE</strong>: You don&#39;t have to use Telerik Backend Services to hit your app’s backend; you can use any HTTP API in a NativeScript app. Telerik Backend Services is convenient for us to use for this tutorial because it lets us spin up HTTP endpoints quickly.</p>
631+
</blockquote>
632+
<h4 class="exercise-start">
633+
<b>Exercise</b>: Add an Angular 2 service
634+
</h4>
635+
636+
<p>Open <code>app/shared/user/user.service.ts</code> and paste in the following code:</p>
637+
<pre><code class="lang-JavaScript">
638+
</code></pre>
639+
<div class="exercise-end"></div>
640+
626641
<h3 id="routing">Routing</h3>
627642

628643
</div>

src/chapters/chapter3.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ To see how this works in action let’s create a few files.
120120
<b>Exercise</b>: Add a model object
121121
</h4>
122122

123-
The first thing we’ll do is add a model object to store user data. Open `app/user/user.service.ts` and paste in the following code:
123+
The first thing we’ll do is add a model object to store user data. Open `app/user/user.ts` and paste in the following code:
124124

125125
``` JavaScript
126126
export class User {
@@ -197,6 +197,26 @@ export class AppComponent {
197197

198198
<div class="exercise-end"></div>
199199

200+
With this setup you now have a `User` class that you can share across pages in your app and even across applications. But a model object that’s four simple lines of code isn’t all that exciting. Where this approach really pays off is when you’re able to share your business logic, and the code that hits your backend systems. In Angular 2 those classes are known as services. Let’s look at them next.
201+
200202
### Services
201203

204+
A login screen isn’t all that useful if it doesn’t actually log users into anything. Therefore, our next task is to take the user’s email address and password, and send them to a backend endpoint to retrieve an authentication token we’ll use later in this guide. We’ll build this functionality as an Angular 2 service.
205+
206+
For the purposes of this tutorial we prebuilt a handful of backend endpoints using [Telerik Backend Services](http://www.telerik.com/platform/backend-services), and we’ll be using those endpoints to make this app functional. Let’s see how they work.
207+
208+
> **NOTE**: You don't have to use Telerik Backend Services to hit your app’s backend; you can use any HTTP API in a NativeScript app. Telerik Backend Services is convenient for us to use for this tutorial because it lets us spin up HTTP endpoints quickly.
209+
210+
<h4 class="exercise-start">
211+
<b>Exercise</b>: Add an Angular 2 service
212+
</h4>
213+
214+
Open `app/shared/user/user.service.ts` and paste in the following code:
215+
216+
``` JavaScript
217+
218+
```
219+
220+
<div class="exercise-end"></div>
221+
202222
### Routing

0 commit comments

Comments
 (0)