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>Now, if the user attempts to login or register with an invalid email address, they’ll see an alert that points out the error. However in order to test out this change you’ll need to do one more thing.</p>
1584
+
<h4class="exercise-start">
1585
+
<b>Exercise</b>: Rebuild your app
1586
+
</h4>
1587
+
1588
+
<p>As we mentioned in chapter 1.4, although the <code>tns livesync</code> command is smart enough to reload your app for most changes you make to your app, the command cannot hot reload your app for all changes—most notably, changes to native files in <code>app/App_Resources</code>, new modules installed with <code>npm install</code>, and new NativeScript plugins.</p>
1589
+
<p>For NativeScript to recognize this new email-validator npm module, type <code>Ctrl+C</code> in your terminal to kill the existing <code>tns livesync</code> watcher if it’s still running, and then use <code>tns run</code> to rebuild your application and deploy it to an emulator or device.</p>
1590
+
<pre><code>tns run ios --emulator
1591
+
</code></pre><p>Or</p>
1592
+
<pre><code>tns run android --emulator
1593
+
</code></pre><p>After the app deploys you can again run the <code>livesync</code> command to setup the watcher again.</p>
<p>After your app launches again, if you type an invalid email address and attempt to login, you should see an alert that prevents the submission:</p>
1600
+
<p><imgsrc="images/chapter5/android/1.png" alt="Validation alert on Android">
1601
+
<imgsrc="images/chapter5/ios/1.png" alt="Validation alert on iOS"></p>
1585
1602
<p>In general npm modules greatly expand the number of things you're able to do in your NativeScript apps. Need date and time formatting? Use <ahref="https://www.npmjs.com/package/moment">moment</a>. Need utility functions for objects and arrays? Use <ahref="https://www.npmjs.com/package/lodash">lodash</a> or <ahref="https://www.npmjs.com/package/underscore">underscore</a>. This code reuse benefit gets even more powerful when you bring NativeScript plugins into the picture.</p>
1586
1603
<blockquote>
1587
1604
<p><strong>WARNING</strong>: Not all npm modules work in NativeScript apps. Specifically, modules that depend on Node.js or browser APIs will not work, as those APIs do not exist in NativeScript. The NativeScript wiki contains a <ahref="https://github.com/NativeScript/NativeScript/wiki/supported-npm-modules">list of some of the more popular npm modules that have been verified to work in NativeScript apps</a>.</p>
Copy file name to clipboardExpand all lines: src/chapters/chapter5.md
+37-2Lines changed: 37 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -79,9 +79,44 @@ if (!this.user.isValidEmail()) {
79
79
80
80
<divclass="exercise-end"></div>
81
81
82
-
Explain this code.
82
+
Now, if the user attempts to login or register with an invalid email address, they’ll see an alert that points out the error. However in order to test out this change you’ll need to do one more thing.
83
83
84
-
TODO: Add images
84
+
<h4class="exercise-start">
85
+
<b>Exercise</b>: Rebuild your app
86
+
</h4>
87
+
88
+
As we mentioned in chapter 1.4, although the `tns livesync` command is smart enough to reload your app for most changes you make to your app, the command cannot hot reload your app for all changes—most notably, changes to native files in `app/App_Resources`, new modules installed with `npm install`, and new NativeScript plugins.
89
+
90
+
For NativeScript to recognize this new email-validator npm module, type `Ctrl+C` in your terminal to kill the existing `tns livesync` watcher if it’s still running, and then use `tns run` to rebuild your application and deploy it to an emulator or device.
91
+
92
+
```
93
+
tns run ios --emulator
94
+
```
95
+
96
+
Or
97
+
98
+
```
99
+
tns run android --emulator
100
+
```
101
+
102
+
After the app deploys you can again run the `livesync` command to setup the watcher again.
103
+
104
+
```
105
+
tns livesync ios --emulator --watch
106
+
```
107
+
108
+
Or
109
+
110
+
```
111
+
tns livesync android --emulator --watch
112
+
```
113
+
114
+
<divclass="exercise-end"></div>
115
+
116
+
After your app launches again, if you type an invalid email address and attempt to login, you should see an alert that prevents the submission:
117
+
118
+

119
+

85
120
86
121
In general npm modules greatly expand the number of things you're able to do in your NativeScript apps. Need date and time formatting? Use [moment](https://www.npmjs.com/package/moment). Need utility functions for objects and arrays? Use [lodash](https://www.npmjs.com/package/lodash) or [underscore](https://www.npmjs.com/package/underscore). This code reuse benefit gets even more powerful when you bring NativeScript plugins into the picture.
0 commit comments