-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
960 lines (867 loc) · 28.4 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>girldevelopit-reveal.js - The GDI HTML Presentation Framework</title>
<meta name="description" content="Girl Develop It framework for easily creating beautiful presentations using HTML in GDI theme. Forked from Hakim El Hattab's reveal.js">
<meta name="author" content="Girl Develop It">
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
<link rel="stylesheet" href="css/reveal.css">
<link rel="stylesheet" href="css/theme/gdicool.css" id="theme">
<!-- For syntax highlighting -->
<!-- light editor--><link rel="stylesheet" href="lib/css/light.css">
<!-- dark editor<link rel="stylesheet" href="lib/css/dark.css">-->
<!-- If use the PDF print sheet so students can print slides-->
<link rel="stylesheet" href="css/print/pdf.css" type="text/css" media="print">
<link rel="icon" type="image/x-icon" href="favicon.ico" />
<!--[if lt IE 9]>
<script src="lib/js/html5shiv.js"></script>
<![endif]-->
</head>
<body>
<div class="reveal">
<!-- Any section element inside of this container is displayed as a slide -->
<div class="slides">
<!-- Opening -->
<section>
<h1>Intro to AngularJS</h1>
<h3>Up and running with fundamentals</h3>
</section>
<!-- Compatibility-->
<section>
<h2>Heads Up</h2>
<p>
Girl Develop It is here to provide affordable and accessible programs to learn software through mentorship and hands-on instruction.</p>
<p class="green">Some "rules"</p>
<ul>
<li>We are here for you!</li>
<li>Every question is important</li>
<li>Help each other</li>
<li>Have fun</li>
</ul>
</section>
<section>
<h2>Introductions</h2>
<p>Tell us about yourself.</p>
<ul>
<li>Who are you?</li>
<li>What do you hope to get out of the class?</li>
<li>If you could make any website, what would it be?</li>
</ul>
</section>
<section>
<h2>You should have:</h2>
<p>A <a href="codepen.io">Codepen account</a>.</p>
<p>For coding at home, a text editor (<a href="atom.io">Atom</a>, <a href="sublimetext.com">Sublime Text</a>)</p>
</section>
<section>
<h2>Four Day Agenda</h2>
<ol>
<li>Angular Basics + Best Practices</li>
<li>Managing Data with Services, Forms</li>
<li>Useful add-ons: UI-Router, UI-Bootstrap, testing</li>
<li>Practice, Quick Detour into Angular 2</li>
</ol>
</section>
<section>
<h2>Day 1</h2>
<ul>
<li>Controllers, directives, filters</li>
<li>Data binding</li>
<li>MVC/MV*</li>
<li>Scope and $scope best practices</li>
</ul>
</section>
<section>
<h2>So WHAT is Angular?</h2>
<ul>
<li class="fragment">Client-side Javascript Framework for Single Page Applications (SPAs)</li>
<li class="fragment">Allows you to extends HTML</li>
<li class="fragment">Data binding!</li>
<li class="fragment">Easy to test</li>
<li class="fragment">Handles it's own dependency injection</li>
</ul>
</section>
<section>
<h2>Also</h2>
<ul>
<li class="fragment">Likes to own everything</li>
<li class="fragment">You'll need to think about page refreshes, back button</li>
<li class="fragment">Also consider performance</li>
<li class="fragment">Use $scope.$watch and two-way data binding sparingly</li>
</ul>
</section>
<section>
<p>index.html</p>
<xml class="fragment">
<pre>
<code><body ng-app="app">
<p>2 + 2 = {{2 + 2}}</p>
</body></code>
</pre>
</xml>
</section>
<section>
<h2>How Angular works</h2>
<ul>
<li class="fragment">Each variable used in a view is added to a $watchers list</li>
<li class="fragment">A digest loop checks for changes on page events</li>
<li class="fragment">This is called "dirty checking"</li>
</ul>
</section>
<section>
<h2>Model View Whatever</h2>
<img src="./css/images/MVW.png" />
</section>
<section>
<h2>Other Tools People Use</h2>
<ul>
<li>Handlebars (Server side view)</li>
<li>Backbone (non-opinionated)</li>
<li>Ember</li>
<li>React (View)</li>
</ul>
</section>
<section>
<h2>Directives</h2>
<p>View components and logic</p>
<pre class="fragment"><code contenteditable class ="javascript">angular.module('app', []).directive('myTooltip', myTooltipFn);</code></pre>
<pre class="fragment"><code><my-tooltip></my-tooltip></code></pre>
<pre class="fragment"><code><div my-tooltip="options"></div></code><pre>
</section>
<section>
<p>index.html</p>
<xml class="fragment">
<pre>
<code><body ng-app="app">
<h1>{{pageTitle}}</h1>
</body></code>
</pre>
</xml>
</section>
<section>
<h2>Built-in directives</h2>
<ul>
<li>ng-app</li>
<li class="fragment">ng-if</li>
<li class="fragment">ng-show/ng-hide</li>
<li class="fragment">ng-click</li>
<li class="fragment">ng-model</li>
<li class="fragment">ng-change</li>
<li class="fragment">ng-repeat</li>
<li class="fragment">ng-controller</li>
</ul>
</section>
<section>
<h2>ng-if</h2>
<pre class="fragment">
<code contenteditable><button ng-if="changesEnabled">Edit</button></code>
</pre>
</section>
<section>
<h2>ng-model</h2>
<p>Two way data binding!</p>
<pre class="fragment">
<code contenteditable><input type="text" ng-model="name"/>
Name: {{name}}</code>
</pre>
</section>
<section>
<h2>ng-click</h2>
<pre class="fragment">
<code contenteditable><a href="" ng-click="openModal()">See details</a></code>
</pre>
</section>
<section>
<h2>ng-change</h2>
<xml class="fragment">
<pre>
<code contenteditable>Start Date:
<input ng-change="updateMinDate()" type="text" uib-datepicker/></code>
</pre>
</xml>
</section>
<section>
<h2>ng-repeat</h2>
<xml class="fragment">
<pre>
<code contenteditable><table>
<tbody>
<tr ng-repeat="account in accounts track by $index">
<td ng-bind="account.name"></td>
</tr>
</tbody>
</table>
</code>
</pre>
</xml>
</section>
<section>
<h2>Let's explore Codepen!</h2>
<p><a href="http://codepen.io/Sinetheta/pen/olBxp">http://codepen.io/Sinetheta/pen/olBxp</a></p>
</section>
<section>
<h2>Controllers</h2>
<p>View logic and scope</p>
<p>Use with ng-controller directive, ng-view, or ui-view (with UI-Router - more on this later!)</p>
</section>
<section>
<p>app.js</p>
<pre class="fragment">
<code contenteditable class ="javascript">angular.module('app', []) .controller("menuController", ['$scope',
function($scope) { $scope.pageTitle =
"Angular Example Site"; }]);
</code>
</pre>
<p>index.html</p>
<pre class="fragment">
<code><!DOCTYPE html><html ng-app>
<head><title>{{pageTitle}}</title></head>
<body>
<div ng-controller="menuController">
<h1>{{pageTitle}}</h1>
</div>
<script src="./app.js">
</body>
</html>
</code>
</pre>
</section>
<section>
<h2>Scope and $scope</h2>
<ul>
<li>An angular application can be made up of multiple modules, each with multiple controllers and directives</li>
<li>Unfortunately, since $scope is shared among all modules in an app, it is easy to pollute and overwrite values</li>
</ul>
</section>
<section>
<h2>'this' and 'as'</h2>
<p>app.js</p>
<pre class="fragment">
<code contenteditable class ="javascript">angular.module('app', []) .controller("menuController", ['$scope',
function($scope) { this.pageTitle =
"Angular Example Site"; }]);
</code>
</pre>
<p>index.html</p>
<pre class="fragment">
<code><!DOCTYPE html><html ng-app>
<head><title>{{pageTitle}}</title></head>
<body>
<div ng-controller="menuController as menuCtrl">
<h1>{{menuCtrl.pageTitle}}</h1>
</div>
<script src="./app.js">
</body>
</html>
</code></pre>
</section>
<section>
<h2>ng-repeat</h2>
<xml class="fragment">
<pre>
<code contenteditable><table ng-controller="accountController as accountCtrl">
<thead>...</thead>
<tbody>
<tr ng-repeat="account in accounts track by $index">
<td ng-bind="account.name"></td>
</tr>
</tbody>
</table></code>
</pre>
</xml>
</section>
<section>
<h2>Filters</h2>
<pre class="fragment"><code contenteditable>{{ name | uppercase }}</code></pre>
<p class="fragment">Sam -> SAM</p>
<pre class="fragment"><code contenteditable>{{ startDate | date:'MM/dd/yyyy' }}</code></pre>
<p class="fragment">new Date() -> 04/26/2016</p>
</section>
<section>
<h2>ng-repeat</h2>
<xml class="fragment">
<pre>
<code contenteditable><table ng-controller="accountController as accountCtrl">
<th ng-repeat="tableLabel in accountCtrl.accountTableLabels">
{{tableLabel | uppercase}}</th>
<tbody>
<tr ng-repeat="account in accounts track by $index |
accountCtrl.balanceOverZero">
<td ng-bind="account.name"></td>
</tr>
</tbody>
</table></code>
</pre>
</xml>
</section>
<section>
<p>app.js</p>
<pre class="fragment">
<code class ="javascript">angular.module('app', []).service("menuService", function() {
this.pageTitle = "Angular Example Site";
})
.controller("menuController", ['$scope', 'menuService',
function($scope, menuService) {
$scope.pageTitle = "Angular Example Site";
}]);
</code>
</pre>
<p>index.html</p>
<pre class="fragment">
<code><!DOCTYPE html>
<html ng-app><head><title>{{pageTitle}}</title></head>
<body>
<div ng-controller="menuController">
<h1>{{pageTitle}}</h1>
</div>
<script src="./app.js">
</body>
</html></code>
</pre>
</section>
<section>
<h2>Codepen Practice!</h2>
<p>Fork this codepen and use six directives you've learned:
<a href="http://codepen.io/arilaen/pen/oxPwQq">http://codepen.io/arilaen/pen/oxPwQq</a>
</p>
<p>Here's the list again (starred directives are required):</p>
<ul>
<li>ng-app</li>
<li class="fragment">ng-controller</li>
<li class="fragment">ng-if</li>
<li class="fragment">ng-show/ng-hide</li>
<li class="fragment">ng-click</li>
<li class="fragment">ng-model</li>
<li class="fragment">ng-change</li>
<li class="fragment">ng-repeat</li>
</ul>
</section>
<section>
<h2>Next time...</h2>
<ul>
<li>Make your own directives!</li>
<li>Services</li>
<li>Forms</li>
</ul>
</section>
<section>
<h2>Intro to Angular Part 2</h2>
<p>Questions/thoughts before we begin?</p>
</section>
<section>
<h2>Day 2</h2>
<ul>
<li>Recap of Basics</li>
<li>Create your own directives!</li>
<li>Forms</li>
</ul>
</section>
<section>
<h2>Recap: WHAT is Angular?</h2>
<ul>
<li class="fragment">Client-side Javascript Framework for Single Page Applications (SPAs)</li>
<li class="fragment">Allows you to extends HTML</li>
<li class="fragment">Data binding!</li>
<li class="fragment">Handles it's own dependency injection</li>
</ul>
</section>
<section>
<h2>Recap: Model View Whatever</h2>
<img class="fragment" src="./css/images/MVW.png" />
<p class="fragment">http://www.techstrikers.com/AngularJS/angularjs-mvc-pattern.php</p>
<p class="fragment">https://plus.google.com/+AngularJS/posts/aZNVhj355G2</p>
</section>
<section>
<h2>Recap: Directives</h2>
<p class="fragment">View components and logic</p>
<pre class="fragment"><code contenteditable class ="javascript">angular.module('app', []).directive('myTooltip', myTooltipFn);</code></pre>
<p class="fragment">Element style</p>
<pre class="fragment"><code><my-tooltip></my-tooltip></code></pre>
<p class="fragment">Attribute style</p>
<pre class="fragment"><code><div my-tooltip="options"></div></code><pre>
</section>
<section>
<h2>Recap: Built-in directives</h2>
<ul>
<li>ng-app</li>
<li class="fragment">ng-if</li>
<li class="fragment">ng-show/ng-hide</li>
<li class="fragment">ng-click</li>
<li class="fragment">ng-model</li>
<li class="fragment">ng-change</li>
<li class="fragment">ng-repeat</li>
<li class="fragment">ng-controller</li>
</ul>
</section>
<section>
<h2>Let's go over yesterday's codepen!</h2>
<p><a href="http://codepen.io/arilaen/pen/oxPwQq">http://codepen.io/arilaen/pen/oxPwQq</a></p>
</section>
<section>
<h2>Recap: Controllers</h2>
<p class="fragment">app.js</p>
<pre class="fragment">
<code contenteditable class ="javascript">angular.module('app', []) .controller("menuController", ['$scope',
function($scope) { this.pageTitle =
"Angular Example Site"; }]);
</code>
</pre>
<p class="fragment">index.html</p>
<pre class="fragment">
<code><!DOCTYPE html><html ng-app>
<head><title>{{pageTitle}}</title></head>
<body>
<div ng-controller="menuController as menuCtrl">
<h1>{{menuCtrl.pageTitle}}</h1>
</div>
<script src="./app.js">
</body>
</html>
</code></pre>
</section>
<section>
<h2>So How Do You Create YOUR OWN Directive?</h2>
<p>There are two types:</p>
<ul>
<li class="fragment">Element: <pre class="fragment">
<code><profile-section></profile-section></code></pre></li>
<li class="fragment">Attribute: <pre class="fragment">
<code><input type="number" model="accountCtrl.percentGoal" percent-mask /></code></pre></li>
</section>
<section>
<h2>Element directives</h2>
<ul>
<li class="fragment">Placeholder for an HTML template</li>
<li class="fragment">Simplest example:
<pre class="fragment">
<code><ng-include="./profile-section-template.html"></ng-include></code>
</pre>
</li>
<li class="fragment">This element directive JUST brings in the template, with no extra logic</li>
<li class="fragment">Results in an extra AJAX request at runtime</li>
<li class="fragment">Avoid this by making your own directives!</li>
</ul>
</section>
<section>
<h2>Attribute directives</h2>
<ul>
<li class="fragment">Add an attribute (logic) to another HTML tag</li>
<li class="fragment">Examples: ng-click, ng-model, etc.</li>
<li class="fragment">Do not include templates</li>
</ul>
</section>
<section>
<h2>Both element and attribute directives...</h2>
<ul>
<li class="fragment">Can include view logic, can even include a controller</li>
<li class="fragment">Can have *isolate scope*</li>
</ul>
</section>
<section>
<h2>Code!</h2>
<pre class="fragment">
<code contenteditable class ="javascript">angular.module('app', []).directive("profileSection", function() {
return {
restrict: 'E', //E for element, A for attribute!,
templateUrl: './profile-section.html',
scope: {},
transclude: true //Has access to everything in parent scope - avoid!
}
};</code>
</pre>
</section>
<section>
<h2>Code with template!</h2>
<pre class="fragment">
<code contenteditable class ="javascript">angular.module('app', []).directive("profileSection", function() {
return {
restrict: 'E',
template: '<div class="profile-section"><h2>Profile</h2></div>',
scope: {}
}
};
</code>
</pre>
</section>
<section>
<h2>Now let's add variables to scope!</h2>
<pre class="fragment">
<code contenteditable class ="javascript">angular.module('app', []).directive("profileSection", function() {
return {
restrict: 'E',
template: 'Name: {{name}}, Age: {{age}}',
scope: {
name: '=name', //or '='
age: '=age' //or '='
}
}
};
</code>
</pre>
</section>
<section>
<h2>And now we can use our directive!</h2>
<pre class="fragment"><code contenteditable><table>
<tbody>
<tr ng-repeat="user in users">
<profileSection name="user.name" age="user.age"></profile-section>
</tr>
</tbody>
</table>
</code>
</pre>
</section>
<section>
<h2>More Examples at Angular Docs</h2>
<p><a href="https://docs.angularjs.org/guide/directive">https://docs.angularjs.org/guide/directive</a>
</section>
<section>
<h2>Your Turn!</h2>
<p>Write your own directive in your codepen</p>
<p>Ideas:</p>
<ul>
<li>A header</li>
<li>A footer</li>
<li>Menu</li>
<li>Link</li>
<li>Description (for a blog post, etc.)</li>
</ul>
</section>
<section>
<h2>More with directives</h2>
<p class="fragment">You can add logic via a controller:</p>
<pre class="fragment">
<code contenteditable class="javascript">angular.module('app', []).directive("profileSection", function() {
return {
restrict: 'E',
template: 'Name: {{name}}, Age: {{age}}',
controller: 'ProfileController' // Angular manages dependencies and will find this with just a string!
scope: {
name: '=name', //or '='
age: '=age' //or '='
}
}
};
</code>
</pre>
</section>
<section>
<h2>More with directives</h2>
<p class="fragment">Or more commonly, with a link function (more on this next class):</p>
<pre class="fragment">
<code contenteditable class="javascript">angular.module('app', []).directive("", function() {
return {
restrict: 'A',
template: 'Name: {{name}}, Age: {{age}}',
scope: {
firstName: '='
lastName: '='
},
link: function(scope, element, attributes) {
scope.name = scope.firstName + ' ' + scope.lastName;
}
}
};</code>
</pre>
</section>
<section>
<h2>'=', '@', '&'</h2>
<p class="fragment">'=' is for two way binding</h2>
<p class="fragment">'&' is for one way binding (usually functions)</p>
<p class="fragment">'@' is for text</h2>
<pre class="fragment">
<code contenteditable class ="javascript">angular.module('app', []).directive("profileSection", function() {
return {
restrict: 'E',
template: 'Name: {{name}}, Age: {{age}}',
scope: {
name: '='
age: '@'
}
}
}; // <profile-section name="user.name" age="20"></profile-section>
</code>
</pre>
</section>
<section>
<h2>Tools for forms</h2>
<ul>
<li>ng-model: Use on inputs to keep track of updates</li>
<li>ng-submit: Runs when you submit a form</li>
<li>Don't just rely on ng-click - user can press enter to submit a form</li>
<li>Can review codepen for an example of this in practice</li>
</ul>
</section>
<section>
<h2>Optional: Save data to a service</h2>
<ul>
<li>Services can be shared across different controllers</li>
<li>Can also load data from/send data to back end, store in local storage, etc.</li>
<li>More on this next class</li>
</ul>
</section>
<section>
<h2>Adventure trip!</h2>
<ul>
<li>Choose your favorite destination for a group trip! <small>Decide how many people can go.</small></li>
<li>Create a model for the travelers <small>(Name, Age, Email, Photo, Has previously visited? Allergies? etc.)</small></li>
<li>Display who's going and # spots remaining</li>
<li>Create a traveler row directive with name, age, etc.</li>
<li>Add a form for people to sign up for the trip</li>
<li>Extra: Hide form when trip is full</li>
<li>Extra: Use two controllers and store data in a service</li>
</ul>
</section>
<section>
<h2>Day 3</h2>
<ul>
<li>Adventure trip!</li>
<li>Review Week 1</li>
<li>Services</li>
</ul>
</section>
<section>
<h2>Day 1</h2>
<ul>
<li>Controllers, directives, filters</li>
<li>Data binding</li>
<li>MVC/MV*</li>
<li>Scope and $scope best practices</li>
</ul>
</section>
<section>
<h2>Day 2</h2>
<ul>
<li>Create your own directives!</li>
<li>Forms</li>
</ul>
</section>
<section>
<p>Codepen review!
<a href="http://codepen.io/arilaen/pen/oxPwQq">http://codepen.io/arilaen/pen/oxPwQq</a>
</p>
</section>
<section>
<h2>Services</h2>
<ul>
<li>Singletons - only one instance is created</li>
<li>Can use built-in services ($http, $cookies)</li>
<li>Can create your own - store or share data</li>
<li>Lazily created - only made when needed</li>
</ul>
</section>
<section>
<p>Making a service</p>
<pre class="fragment">
<code class ="javascript">
angular.module('app', []).service("menuService", function() {
this.pageTitle = "Angular Example Site";
})
.controller("menuController", ['$scope', 'menuService',
function($scope, menuService) {
$scope.pageTitle = "Angular Example Site";
}]);
</code>
</pre>
<p>index.html</p>
<pre class="fragment">
<code><!DOCTYPE html>
<html ng-app><head><title>{{pageTitle}}</title></head>
<body>
<div ng-controller="menuController">
<h1>{{pageTitle}}</h1>
</div>
<script src="./app.js">
</body>
</html></code>
</pre>
</section>
<section>
<h2>Built-in Services</h2>
<ul>
<li class="fragment">$http</li>
<li class="fragment">$cookies</li>
<li class="fragment">$localStorage</li>
<li class="fragment">$window + $document</li>
<li class="fragment">$log</li>
<li class="fragment">$state (external - comes with ui-router module)</li>
</ul>
</section>
<section>
<h2>$http</h2>
<pre class="fragment">
<code contenteditable class ="javascript">
angular.module('app', []).service("todoService", ['$http',
function($http) {
var service = this;
this.getTodos = $http.get('http://jsonplaceholder.typicode.com/todos');
this.todos = [];
function init() {
this.getTodos().then(function(data) {
service.todos = data;
});
}
init();
}]);
</code>
</pre>
</section>
<section>
<h2>$http</h2>
<pre class="fragment">
<code contenteditable class ="javascript">
angular.module('app', [])
.service("todoService", todoService)
.controller("todoController", ['$menuService',
function($menuService) {
this.todos = menuService.todos;
}]);
</code>
</pre>
</section>
<section>
<h2>What then?</h2>
<p class="fragment">Asynchronous vs. Synchronous Code</p>
<p class="fragment">Most of your code is synchronous - runs sequentially</p>
<pre class="fragment"><code class ="javascript">var data = [{id: 0, name: 1}];</code></pre>
<pre class="fragment"><code class ="javascript">console.log(data.name);</code></pre>
</section>
<section>
<h2>What then?</h2>
<p class="fragment">Asynchronous vs. Synchronous Code</p>
<p>Most of your code is synchronous - runs sequentially</p>
<pre class="fragment">
<code class ="javascript">var data = [{id: 0, name: 1}];</code></pre>
<pre class="fragment">
<code class ="javascript">console.log(data.name);</code></pre>
</section>
<section>
<h2>Asynchronous Code + Promises?</h2>
<p>For external calls, use promises and callbacks</p>
<pre>
<code class ="javascript">$http.get('/posts').then(function(result) {...})</code></pre>
</section>
<section>
<h2>$http</h2>
<pre class="fragment">
<code contenteditable class ="javascript">angular.module('app', [])
.service("todoService", todoService)
.controller("todoController", ['$menuService',
function($menuService) {
this.todos = menuService.todos;
this.addTodo = menuService.addTodo;
this.updateTodo = menuService.updateTodo;
this.saveTodo = menuService.saveTodo;
}]);
</code>
</pre>
</section>
<section>
<h2>Practice</h2>
<p>Let's put it all together and use services with a form, in codepen!</p>
<p>
<a href="http://codepen.io/arilaen/pen/oxPwQq">http://codepen.io/arilaen/pen/oxPwQq</a>
</p>
</section>
<section>
<h2>Day 4</h2>
<ul>
<li>Components</li>
<li>$scope.$watch</li>
<li>Review + Trip planning site!</li>
</ul>
</section>
<section>
<h2>Components</h2>
<ul>
<li class="fragment">Introduced in Angular 1.5; big part of Angular 2</li>
<li class="fragment">Type of element directive</li>
<li class="fragment">In the future, Angular will be all components - no controllers, just components and attribute directives</li>
<li class="fragment">MVComponent?</li>
</ul>
</section>
<section>
<h2>Components</h2>
<pre class="fragment">
<code contenteditable class ="javascript">angular.module('app')
.component('heroDetail', {
templateUrl: 'heroDetail.html',
controller: HeroDetailController,
bindings: {
hero: '='
}
});
</code>
</pre>
</section>
<section>
<h2>$scope.$watch</h2>
<p class="fragment">Allows us to define our own two-way data binding!</p>
<pre class="fragment">
<code contenteditable class ="javascript">angular.module('app', [])
.controller("todoController", ['$scope',
function($scope) {
$scope.hours = 10;
$scope.cost = $scope.hours * 3;
$scope.$watch(function(newValue, oldValue) {
$scope.cost = $scope.hours * 3;
});
}]);
</code>
</pre>
</section>
<section>
<p>Practice! Time to finish your trip apps! You can follow along with me here:
<a href="http://codepen.io/arilaen/pen/oxPwQq">http://codepen.io/arilaen/pen/oxPwQq</a></p>
</section>
<section>
<h2>Next steps</h2>
<ul>
<li><a href="https://angular.io/docs/ts/latest/quickstart.html">Learn about Angular 2</a></li>
<li>Try out ui-router and ui-bootstrap</li>
<li>Create your own Angular app and deploy it on heroku with node and npm</li>
</ul>
</section>
<section>
<h2>Resources</h2>
<ul>
<li><a href="https://docs.angularjs.org/api">Angular API Docs</a></li>
<li><a href="https://www.codeschool.com/courses/shaping-up-with-angular-js">Code School</a></li>
<li><a href="https://egghead.io/series/angularjs-app-from-scratch-getting-started">Egghead.io</a></li>
<li><a href="https://github.com/johnpapa/angular-styleguide/blob/master/a1/README.md">John Papa's Angular Style Guide</a></li>
<ul>
</section>
</div>
<footer>
<div class="copyright">
Intro to AngularJS -- Girl Develop It Boston --
<a rel="license" href="http://creativecommons.org/licenses/by-nc/3.0/deed.en_US"><img alt="Creative Commons License" style="border-width:0" src="http://i.creativecommons.org/l/by-nc/3.0/80x15.png" /></a>
</div>
</footer>
</div>
<script src="lib/js/head.min.js"></script>
<script src="js/reveal.min.js"></script>
<script>
// Full list of configuration options available here:
// https://github.com/hakimel/reveal.js#configuration
Reveal.initialize({
controls: true,
progress: true,
history: true,
theme: Reveal.getQueryHash().theme, // available themes are in /css/theme
transition: Reveal.getQueryHash().transition || 'default', // default/cube/page/concave/zoom/linear/none
// Optional libraries used to extend on reveal.js
dependencies: [
{ src: 'lib/js/classList.js', condition: function() { return !document.body.classList; } },
{ src: 'plugin/markdown/showdown.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
{ src: 'plugin/markdown/markdown.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
{ src: 'plugin/highlight/highlight.js', async: true, callback: function() { hljs.initHighlightingOnLoad(); } },
{ src: 'plugin/zoom-js/zoom.js', async: true, condition: function() { return !!document.body.classList; } },
{ src: 'plugin/notes/notes.js', async: true, condition: function() { return !!document.body.classList; } }
]
});
</script>
</body>
</html>