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
+10-9Lines changed: 10 additions & 9 deletions
Original file line number
Diff line number
Diff line change
@@ -953,8 +953,8 @@ <h4 class="exercise-start">
953
953
<p>Your app now has a fully functional registration process, but users can’t do anything with the accounts they create. Our next step is to allow the users to login and navigate to a new list page. And to do that we need to introduce the concept of routing.</p>
954
954
<h3id="routing">Routing</h3>
955
955
<p>Most of the Angular 2 concepts you’ve used in the last few sections are the same regardless of whether you’re building for the web or native apps. You are even able to share model objects and services directly between the two environments.</p>
956
-
<p>However, routing is different, as there are some fundamental differences between how the concept of routing works on the web and in apps. Routing on the web revolves around the concept of a URL, but in a native app there is no browser. Likewise, native apps have concepts that aren’t present in the browser, such as Android’s hardware back button, or iOS’s swipe left-to-right gesture to go back.</p>
957
-
<p>Because of that, routing in NativeScript needs to work a bit differently. The main difference is that you must designate certain Angular components in your app as “pages”, which in Groceries are stored in the <code>pages</code> folder. Let’s look at the code needed to make this work, and then step by and discuss why NativeScript takes the approach that it does.</p>
956
+
<p>However, routing is a bit different, as there are some fundamental differences between how the concept of routing works on the web and in apps. Routing on the web revolves around the concept of a URL, but in a native app there is no browser. Likewise, native apps have concepts that aren’t present in the browser, such as Android’s hardware back button, or iOS’s swipe left-to-right gesture to go back.</p>
957
+
<p>Because of that, even though NativeScript uses the same Angular 2 routing APIs, you must designate certain Angular components in your app as “pages”—which is something you don’t necessarily have to do in an Angular 2 web app. In Groceries the code for these pages is in the app’s <code>pages</code> folder. Let’s look at this works in an exercise, and then step back and discuss why NativeScript takes the approach that it does.</p>
958
958
<h4class="exercise-start">
959
959
<b>Exercise</b>: Setting up routing
960
960
</h4>
@@ -965,7 +965,7 @@ <h4 class="exercise-start">
965
965
<pre><codeclass="lang-TypeScript">import {User} from "../../shared/user/user";
966
966
import {UserService} from "../../shared/user/user.service";
967
967
</code></pre>
968
-
<p>Now that <code>app.component.ts</code> is empty, let’s add in the appropriate Angular 2 routing code. Open app/app.component.ts back up and paste in the following code:</p>
968
+
<p>Now that <code>app.component.ts</code> is empty, let’s add in the appropriate Angular 2 routing code. Open <code>app/app.component.ts</code> back up and paste in the following code:</p>
969
969
<pre><codeclass="lang-TypeScript">import {Component} from "angular2/core";
970
970
import {RouteConfig} from "angular2/router";
971
971
import {NS_ROUTER_DIRECTIVES, NS_ROUTER_PROVIDERS} from "nativescript-angular/router";
@@ -984,12 +984,10 @@ <h4 class="exercise-start">
984
984
</code></pre>
985
985
<divclass="exercise-end"></div>
986
986
987
-
<p>The main new concept here is the <code>@RouteConfig</code> decorator, which you use to provide a list of all routes that are present in your app. Currently you only have one route, which is why <code>@RouteConfig</code> contains a single entry.</p>
988
-
<blockquote>
989
-
<p><strong>TIP</strong>: If you haven’t played with Angular 2 routing before, you can refer to <ahref="https://angular.io/docs/ts/latest/tutorial/toh-pt5.html">Angular’s tutorial on the topic</a> for some background.</p>
990
-
</blockquote>
991
-
<p>The other new concept in this example is <code><page-router-outlet></code>, which is your app’s first directive. You can check out Angular’s docs for <ahref="https://angular.io/docs/ts/latest/api/core/Directive-decorator.html">details on what directives do</a>, but the simplest way to think of them is as something that can affect the markup you put in your <code>template</code>—in this case <code><page-router-outlet></code>.</p>
992
-
<p>Angular 2 provides a <code><router-outlet></code> directive for web apps, and NativeScript extends that directive with its own <code><page-router-outlet></code> directive that handles the unique environment of iOS and Android apps. To see how it works let’s add another page.</p>
987
+
<p>If you haven’t played with routing in Angular 2 before, you can refer to <ahref="https://angular.io/docs/ts/latest/tutorial/toh-pt5.html">Angular’s tutorial on the topic</a> for some background, but the basic concept is you include a <code>@RouteConfig</code> decorator, and pass that decorator a list of all routes that are present in your app. Currently you only have one route, which is why <code>@RouteConfig</code> contains a single entry.</p>
988
+
<p>The other new concept in this example is the <code><page-router-outlet></code> tag, which is your app’s first directive. You can again check out Angular’s docs if you want <ahref="https://angular.io/docs/ts/latest/api/core/Directive-decorator.html">detailed information on what directives are and do</a>, but the simplest way to think of a directive is as something that can affect the markup you put in your <code>template</code>—in this case <code><page-router-outlet></code>.</p>
989
+
<p>And to take a step back, that directive, <code><page-router-outlet></code> is the only difference in routing between the routing code above and the <ahref="https://github.com/tjvantoll/Groceries/blob/master/app/app.component.ts">same code in the Groceries web implementation</a>. Angular 2 provides a <code><router-outlet></code> directive for web apps, and NativeScript extends that directive with its own <code><page-router-outlet></code> directive that handles the unique environment of iOS and Android apps. The great thing about NativeScript is those details are transparent to you as a developer.</p>
990
+
<p>Let’s add another page to see the routing in action.</p>
993
991
<h4class="exercise-start">
994
992
<b>Exercise</b>: Create the list page
995
993
</h4>
@@ -1067,6 +1065,9 @@ <h4 class="exercise-start">
1067
1065
<p><imgsrc="images/chapter3/android/7.gif" alt="Navigating on Android">
1068
1066
<imgsrc="images/chapter3/ios/7.gif" alt="Navigating on iOS"></p>
1069
1067
<p>The power of NativeScript is you have the ability to use the same Angular conventions that you’d use in a web app—<code>@RouteConfig</code>, <code>Router</code>, and so forth—yet get an app that fits right in on iOS and Android. Notice how on Android the hardware back button works as expected, and how your iOS app uses built-in iOS animations and conventions such as the back button.</p>
1068
+
<blockquote>
1069
+
<p><strong>TIP</strong>: There are other ways to share code between native and web apps besides the <code>shared</code> folder convention Groceries uses. For an approach that places web and native code in the same codebase, that also provides some additional tooling around testing and internationalization, check out <ahref="https://github.com/NathanWalker/angular2-seed-advanced">Nathan Walker’s advanced Angular 2 seed project</a>.</p>
1070
+
</blockquote>
1070
1071
<p>And we’re just getting started. NativeScript provides a number of other ways to tie into native device functionality out of the box through NativeScript modules. Let’s look at how they work.</p>
Copy file name to clipboardExpand all lines: src/chapters/chapter3.md
+9-7Lines changed: 9 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -498,9 +498,9 @@ Your app now has a fully functional registration process, but users can’t do a
498
498
499
499
Most of the Angular 2 concepts you’ve used in the last few sections are the same regardless of whether you’re building for the web or native apps. You are even able to share model objects and services directly between the two environments.
500
500
501
-
However, routing is different, as there are some fundamental differences between how the concept of routing works on the web and in apps. Routing on the web revolves around the concept of a URL, but in a native app there is no browser. Likewise, native apps have concepts that aren’t present in the browser, such as Android’s hardware back button, or iOS’s swipe left-to-right gesture to go back.
501
+
However, routing is a bit different, as there are some fundamental differences between how the concept of routing works on the web and in apps. Routing on the web revolves around the concept of a URL, but in a native app there is no browser. Likewise, native apps have concepts that aren’t present in the browser, such as Android’s hardware back button, or iOS’s swipe left-to-right gesture to go back.
502
502
503
-
Because of that, routing in NativeScript needs to work a bit differently. The main difference is that you must designate certain Angular components in your app as “pages”, which in Groceries are stored in the `pages` folder. Let’s look at the code needed to make this work, and then step by and discuss why NativeScript takes the approach that it does.
503
+
Because of that, even though NativeScript uses the same Angular 2 routing APIs, you must designate certain Angular components in your app as “pages”—which is something you don’t necessarily have to do in an Angular 2 web app. In Groceries the code for these pages is in the app’s `pages` folder. Let’s look at this works in an exercise, and then step back and discuss why NativeScript takes the approach that it does.
504
504
505
505
<h4class="exercise-start">
506
506
<b>Exercise</b>: Setting up routing
@@ -517,7 +517,7 @@ import {User} from "../../shared/user/user";
Now that `app.component.ts` is empty, let’s add in the appropriate Angular 2 routing code. Open app/app.component.ts back up and paste in the following code:
520
+
Now that `app.component.ts` is empty, let’s add in the appropriate Angular 2 routing code. Open `app/app.component.ts` back up and paste in the following code:
521
521
522
522
```TypeScript
523
523
import {Component} from"angular2/core";
@@ -539,13 +539,13 @@ export class AppComponent {}
539
539
540
540
<divclass="exercise-end"></div>
541
541
542
-
The main new concept here is the `@RouteConfig` decorator, which you use to provide a list of all routes that are present in your app. Currently you only have one route, which is why `@RouteConfig` contains a single entry.
542
+
If you haven’t played with routing in Angular 2 before, you can refer to [Angular’s tutorial on the topic](https://angular.io/docs/ts/latest/tutorial/toh-pt5.html) for some background, but the basic concept is you include a `@RouteConfig` decorator, and pass that decorator a list of all routes that are present in your app. Currently you only have one route, which is why `@RouteConfig` contains a single entry.
543
543
544
-
> **TIP**: If you haven’t played with Angular 2 routing before, you can refer to [Angular’s tutorial on the topic](https://angular.io/docs/ts/latest/tutorial/toh-pt5.html) for some background.
544
+
The other new concept in this example is the `<page-router-outlet>` tag, which is your app’s first directive. You can again check out Angular’s docs if you want [detailed information on what directives are and do](https://angular.io/docs/ts/latest/api/core/Directive-decorator.html), but the simplest way to think of a directive is as something that can affect the markup you put in your `template`—in this case `<page-router-outlet>`.
545
545
546
-
The other new concept in this example is`<page-router-outlet>`, which is your app’s first directive. You can check out Angular’s docs for [details on what directives do](https://angular.io/docs/ts/latest/api/core/Directive-decorator.html), but the simplest way to think of them is as something that can affect the markup you put in your `template`—in this case `<page-router-outlet>`.
546
+
And to take a step back, that directive,`<page-router-outlet>`is the only difference in routing between the routing code above and the [same code in the Groceries web implementation](https://github.com/tjvantoll/Groceries/blob/master/app/app.component.ts). Angular 2 provides a `<router-outlet>` directive for web apps, and NativeScript extends that directive with its own `<page-router-outlet>` directive that handles the unique environment of iOS and Android apps. The great thing about NativeScript is those details are transparent to you as a developer.
547
547
548
-
Angular 2 provides a `<router-outlet>` directive for web apps, and NativeScript extends that directive with its own `<page-router-outlet>` directive that handles the unique environment of iOS and Android apps. To see how it works let’s add another page.
548
+
Let’s add another page to see the routing in action.
549
549
550
550
<h4class="exercise-start">
551
551
<b>Exercise</b>: Create the list page
@@ -650,4 +650,6 @@ After this change you can now navigate between the login and list pages in your
650
650
651
651
The power of NativeScript is you have the ability to use the same Angular conventions that you’d use in a web app—`@RouteConfig`, `Router`, and so forth—yet get an app that fits right in on iOS and Android. Notice how on Android the hardware back button works as expected, and how your iOS app uses built-in iOS animations and conventions such as the back button.
652
652
653
+
> **TIP**: There are other ways to share code between native and web apps besides the `shared` folder convention Groceries uses. For an approach that places web and native code in the same codebase, that also provides some additional tooling around testing and internationalization, check out [Nathan Walker’s advanced Angular 2 seed project](https://github.com/NathanWalker/angular2-seed-advanced).
654
+
653
655
And we’re just getting started. NativeScript provides a number of other ways to tie into native device functionality out of the box through NativeScript modules. Let’s look at how they work.
0 commit comments