/
index.html
1053 lines (986 loc) · 42.1 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
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!doctype html>
<!--
Author: Sebastian Mancke
License: CreativeCommons Attribution-ShareAlike, http://creativecommons.org/licenses/by-sa/3.0/
--><html ng-app="presentation">
<head>
<title>AngularJS Einführung</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=800" />
<link href="./lib/bootstrap.css" rel="stylesheet" media="screen"/>
<script src="./lib/jquery.min.js"></script>
<script src="./lib/bootstrap.min.js"></script>
<script src="./lib/angular.min.js"></script>
<script src="./lib/angular-route.min.js"></script>
<script src="./lib/angular-mocks-http.js"></script>
<script src="./lib/angular-locale_de-de.js"></script>
<script src="./lib/angular-resource.min.js"></script>
<script src="./lib/angular-ui-router.min.js"></script>
<link href="./lib/prettify/prettify.css" rel="stylesheet" media="screen"/>
<script src="./lib/prettify/prettify.js"></script>
<script src="./tarent-slide/tarent-slide.js"></script>
<link href="./tarent-slide/tarent-slide.css" rel="stylesheet"/>
<!-- <script src="./lib/live.js"></script>
live reload
-->
<script>
/**
* This directive allows us to list code from the live presentation examples
* within a pretified listing.
*/
app.directive('listingOf', [function () {
return {
restrict: 'AE',
link: function (scope, elem, attrs) {
var targetElement = $( '#' + attrs.listingOf );
var html = targetElement.html();
html = html.replace(/^[\t ]*\n+/, ""); //remove empty lines at begin
while (html[0] == ' ') {
html = html.replace(/^ /, ""); //remove indentationn of first lines
html = html.replace(/\n /g, "\n"); //remove indentationn of all other lines
}
// split long lines on white spaces
lines = html.split("\n");
html = '';
for (var i=0; i<lines.length; i++) {
var pos = lines[i].lastIndexOf(' ', 85)
if (lines[i].length > 85 && pos != -1) {
html += lines[i].substring(0, pos);
html += "\n";
while (lines[i] == ' ') {
html += ' ';
}
html += ' ';
html += lines[i].substring(pos);
} else {
html += lines[i];
}
html += "\n";
}
html = html.trim();
html = html.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
html = html.replace(/\s?ng-binding/g, '')
.replace(/\s?ng-pristine/g, '')
.replace(/\s?ng-scope/g, '')
.replace(/\s?ng-valid/g, '')
.replace(/\s?ng-untouched/g, '')
.replace(/ class="\s?"/g, '');
html = html.replace(/\n.*!-- ngIf:.*/g, '');
html = html.replace(/\n.*!-- ngRepeat:.*/g, '');
elem.html(html+elem.html());
elem.addClass('prettyprint');
}
}
}]);
</script>
</head>
<body onload="prettyPrint()">
<slides>
<slide>
<img style="position: relative; top: 200px; left: 0px" src="res/angular_logo.png">
<div style="position: relative; top: 50px; right: 20px; margin: auto;">
<p>
<h2 style="text-align: right; font-size: 80px; line-height: 80px;">AngularJS</h2>
<h2 style="text-align: right">Sebastian Mancke</h2>
<h6 style="text-align: right">Creative Commons BY-SA 3.0</h6>
</p>
</div>
</slide>
<slide>
<div lang="de">
<h1>AngularJS - Einordnung</h1>
<br>
<h2>Kernkonzepte</h2>
<ul>
<li>Umfassendes MVC Framework</li>
<li>Ausgerichtet auf Single Page Apps</li>
<li>Browser-Seitiges Templating</li>
<li>Designed auf Testbarkeit</li>
</ul>
<br>
<h2>Abgrenzung</h2>
<ul>
<li>zu JQuery: Deklarativ, wenig Hacking im DOM</li>
<li>zu Knockout.JS: Viel umfassender</li>
</ul>
</div>
<div lang="en">
<h1>AngularJS</h1>
<br>
<h2>Key concepts</h2>
<ul>
<li>Comprehensive MVC framework</li>
<li>Targeting single page apps</li>
<li>In browser templating</li>
<li>Designed for testability</li>
</ul>
<br>
<h2>Segregation</h2>
<ul>
<li>to JQuery: Declarative, without hacking in the DOM</li>
<li>to Knockout.JS: More comprehensive</li>
</ul>
</div>
</slide>
<slide>
<h1 lang="de">Die Basics</h1>
<h1 lang="en">Basics</h1>
<h2 lang="de">Deklaration und Includes</h2>
<h2 lang="en">Declaration and Includes</h2>
<br>
<pre class="prettyprint" style="padding-bottom: 0px">
<html ng-app="presentation">
...
<script src="./lib/jquery.min.js"></script>
<script src="./lib/angular.min.js"></script>
<script>
var app = angular.module('presentation', []);
</script></pre>
<br>
<ul lang="de">
<li>Die <code>ng-app</code> Anweisung initialisiert die Anwendung</li>
<li>angular.min.js ~ 97K</li>
<li>Initialisierungszeit inkl. JQuery: ~250ms</li>
<li>Nutzt JQuery, kann aber auch ohne (eingeschränkte Funktionalität)</li>
</ul>
<ul lang="en">
<li>The <code>ng-app</code> initializes the application</li>
<li>angular.min.js ~ 97K</li>
<li>Loading an initialization time incl. JQuery: ~250ms</li>
<li>Uses JQuery, but also has a minimal build in replacement (reduced functionality)</li>
</ul>
</slide>
<slide>
<div id="simpleBindingExample">
<h1 lang="de">Einfache Bindings {{demo}}</h1>
<h1 lang="en">Simple bindings {{demo}}</h1>
<div lang="de">AngularJS ermöglicht ein Templating direkt im Browser.</div>
<div lang="en">AngularJS utilizes templating in the browser.</div>
<p>Demo: {{demo}}</p>
<input class="form-control" type="text" ng-model="demo">
</div>
<hr/>
<pre listing-of="simpleBindingExample"></pre>
</slide>
<slide>
<h1 lang="de">Bindings - weitere Beispiele</h1>
<h1 lang="en">Bindings - further examples</h1>
<div lang="de">AngularJS verfügt über eine Reihe praktischer Hilfsmittel für Bindings:</div>
<div lang="en">AngularJS has a lot of useful tools for the bindings:</div>
<code>ng-model</code>, <code>ng-if</code>, <code>ng-init</code>
<br><br>
<pre listing-of="checkboxBindingExample">
<h3 ng-if="state == 'enabled'">AngularJS is cool!</h3></pre>
<hr>
<div id="checkboxBindingExample">
<input type="checkbox" ng-model="state" ng-true-value="'enabled'" ng-false-value="'disabled'" ng-init="state='enabled'">
<p>State: {{state}}</p>
<select class="form-control" ng-model="state">
<option>enabled</option>
<option>disabled</option>
</select>
<h3 ng-if="state == 'enabled'">AngularJS is cool!</h3>
</div>
</slide>
<slide>
<h1 lang="de">Bindings - classen und styles</h1>
<h1 lang="en">Bindings - classes and styles</h1>
<div lang="de">Für typische HTML-Aufgaben hat AngularJS passende Direktiven.</div>
<div lang="en">AngularJS has directives for all typical HTML styling work.</div>
<br>
<h2><code>ng-class</code></h2>
<pre listing-of="styleBindingExample"></pre>
<div id="styleBindingExample">
<input type="checkbox" ng-model="everyThingOk" ng-init="everyThingOk=true">
<span ng-class="{'alert-success':everyThingOk, 'alert-danger':!everyThingOk }" class="alert">This is the message</span>
</div>
<br>
<hr/>
<h2><code>ng-style</code></h2>
<pre listing-of="styleBindingExample2"></pre>
<div id="styleBindingExample2">
<button class="btn" ng-click="myStyle={color:'red', 'font-weight':'bold'}">red</button>
<button class="btn" ng-click="myStyle={'color':'blue'}">blue</button>
<span ng-style="myStyle">Sample text, myStyle={{myStyle}}</span>
</div>
</slide>
<script id="bindingExample1">
app.controller('BindingsCtrl1', function($scope) {
console.log('init controller ..');
$scope.answer = 42;
$scope.anyFunction = function () {
$scope.question = ' is the answer!';
}});
</script>
<slide>
<h1>Controller</h1>
<h3 lang="de">Logik ist in AngularJS in Controllern organisiert.</h3>
<h3 lang="en">The logic is organized within controllers.</h3>
<ul lang="de">
<li>Controller definieren einen <b>Scope</b> für Variablen.</li>
<li>Initialisierungscode wird direkt ausgeführt.</li>
<li>Funktionen werden im <code>$scope</code> agbelegt.</li>
</ul>
<ul lang="en">
<li>A controller defines the <b>scope</b> for variables.</li>
<li>Initialization code will be executed directly.</li>
<li>Functions are stored in the <code>$scope</code> variable.</li>
</ul>
<hr/>
<div class="container-fluid">
<div class="row">
<div class="col-md-8">
<pre listing-of="bindingExample1"></pre>
</div>
<div class="col-md-offset-1 col-md-3" id="bindingExampleHtml1">
<div ng-controller="BindingsCtrl1">
<button type="button" class="btn" ng-click="anyFunction()">Click me</button>
<h3>{{answer}}{{question}}</h3>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<pre listing-of="bindingExampleHtml1"></pre>
</div>
</div>
</div>
</slide>
<script id="formatterController">
app.controller('FormatterCtrl', function($scope) {
$scope.number = 42;
$scope.time = new Date();
});
app.filter('custom', function() {
return function(value) {
return '-' + value +'.00 bli bla';
}
})
</script>
<slide ng-controller="FormatterCtrl">
<h1>Formatter</h1>
<h3 lang="de">Zur Formatierung von Werten gibt es Formater.</h3>
<h3 lang="en">Formatters are used for displaying numbers and currencies.</h3>
<pre listing-of="formatterController"></pre>
<pre listing-of="formatterControllerUsage"></pre>
<hr/>
<div id="formatterControllerUsage">
<div>Number: {{number | number:4}}</div>
<div>Currency: {{number | currency}}</div>
<div>Custom: {{number | custom}}</div>
<div>Time: {{time | date:'medium'}}</div>
</div>
</slide>
<script id="repeatController">
app.controller('RepeatController', function($scope) {
$scope.persons = [
{first: 'Arthur', last: 'Dent'},
{first: 'Zaphod', last: 'Beeblebrox'},
{first: 'Marvin', last: 'robot'},
]});
</script>
<slide>
<h1 lang="de">Iteration über Daten</h1>
<h1 lang="en">Iteration over data</h1>
<h3 lang="de">Mit <code>ng-repeat</code> lassen sich einfach Tabellen und Listen aufbauen.</h3>
<h3 lang="en">Tables can be created using <code>ng-repeat</code>.</h3>
<pre listing-of="repeatController"></pre>
<pre class="prettyprint">
<table ng-controller="RepeatController">
<tr ng-repeat="person in persons">
<td>{​{person.first}}</td> <td>{​{person.last}}</td>
</tr>
</table></pre>
<table class="table table-striped table-bordered" ng-controller="RepeatController">
<tr ng-repeat="person in persons">
<td>{{person.first}}</td>
<td>{{person.last}}</td>
</tr>
</table>
</slide>
<slide ng-controller="RepeatController">
<h1 lang="de">Iteration - Filter + Sortierung</h1>
<h1 lang="en">Iteration - filter + sorting</h1>
<h3 lang="de">Filter und Sortierung lassen sich einfach einbauen.</h3>
<h3 lang="en">Filtering and sorting is very easy.</h3>
<pre listing-of="searchOrder"></pre>
<pre listing-of="searchFilter"></pre>
<pre class="prettyprint"><tr ng-repeat="person in persons | orderBy:orderField | filter: filterText"></pre>
<form class="form-inline" role="form">
<div class="form-group" id="searchOrder" >
<select class="form-control" ng-model="orderField">
<option>first</option>
<option>last</option>
</select>
</div>
<div class="form-group" id="searchFilter" >
<input class="form-control" type="text" ng-model="filterText">
</div>
</form>
<br>
<table class="table table-striped table-bordered" >
<tr ng-repeat="person in persons | orderBy:orderField | filter: filterText">
<td>{{person.first}}</td>
<td>{{person.last}}</td>
</tr>
</table>
</slide>
<slide>
<div lang="de">
<h1>Scopes</h1>
<h2>Was sind Scopes?</h2>
<ul>
<li>Scopes sind die AngularJS-Datenobjekte, die das Modell beinhalten.</li>
<li>Jeder Ausdruck wird im Kontext eines Scope ausgeführt.</li>
</ul>
<h2>Child Scopes</h2>
<ul>
<li>Die Scopes sind hierarchisch entlang des DOM geschachtelt.</li>
<li>Geschachtelte Scopes erben Properties des übergeordneten Scope.</li>
<li>Eigene Properties sind nach außen nicht sichtbar.</li>
</ul>
<h2>Isolierte Scopes</h2>
<ul>
<li>Erben keine Daten.</li>
<li>Können aber Properties über ein Mapping an Parent Scope binden.</li>
</ul>
</div>
<div lang="en">
<h1>Scopes</h1>
<h2>What are scopes?</h2>
<ul>
<li>Scopes are the AngularJS data objects holding the model.</li>
<li>Every function call is done in the context of a scope.</li>
</ul>
<h2>Child scopes</h2>
<ul>
<li>Scopes can be nested along the DOM's hierarchy.</li>
<li>Nested scopes inherit the properties of the parent scope.</li>
<li>The self defined properties are not visible outside.</li>
</ul>
<h2>Isolated Scopes</h2>
<ul>
<li>They do not inherit properties by default,</li>
<li>but they can bind properties of the parent scope through a mapping.</li>
</ul>
</div>
</slide>
<slide>
<h1 lang="de">Änderungen überwachen</h1>
<h1 lang="en">Observing changes</h1>
<h2><code>$scope.$watch()</code></h2>
<h3 lang="de">Mit $watch() kann das Datenmodell überwacht werden.</h3>
<h3 lang="en">The model can be observed by $watch().</h3>
<div lang="de">Verwendung:</div> <div lang="en">Usage:</div> <code>$watch(watchExpression, [listener], [objectEquality]);</code>
<br>
<br>
<h2><code>$scope.$watchCollection()</code></h2>
<h3 lang="de">Beobachtung der Inhalte von Collections.</h3>
<h3 lang="en">Observing the contents of collections.</h3>
<div lang="de">Verwendung:</div> <div lang="en">Usage:</div> <code>$watchCollection(obj, listener);</code>
<hr>
<pre class="prettyprint">
$scope.$watch('backlogItems', function(newValue, oldValue) {
console.log('user has modified "$scope.backlogItems" ..');
..
}, true);</pre>
</slide>
<slide>
<div lang="de">
<h1><code>$scope.$apply()</code></h1>
<h3>Manipulationen am Datenmodell müssen immer im Kontext von
AngularJS erfolgen. Sonst erfolgt kein Update der View.</h3>
<br>
<h3>Dies kann über <code>$scope.$apply()</code> erzwungen werden.</h3>
<br>
<h3>Häufigste Anwendung:
<ul>
<li>window.setTimeout()</li>
<li>Native DOM-Events</li>
<li>Einbindung vorhandener Komponenten</li>
</ul>
</h3>
</div>
<div lang="en">
<h1><code>$scope.$apply()</code></h1>
<h3>Manipulation of the model has to take place in the call context of AngularJS. Otherwise no view updates are triggered.</h3>
<br>
<h3>This can be forced by <code>$scope.$apply()</code>.</h3>
<br>
<h3>Most common for:
<ul>
<li>window.setTimeout()</li>
<li>Native DOM-Events</li>
<li>Integration of existing components</li>
</ul>
</h3>
</div>
</slide>
<script id="svgController">
app.controller('SVGCtrl', function($scope) {
var shift = 135;
$scope.circle = { r:130, x: shift, y: shift };
function update() {
$scope.date = new Date();
var sec = $scope.date.getSeconds() + $scope.date.getMilliseconds()/1000;
var min = $scope.date.getMinutes() + $scope.date.getSeconds()/60;
var h = $scope.date.getHours()%12 + $scope.date.getMinutes()/60;
$scope.sec = { x: shift + 100 * Math.cos(sec/60 * Math.PI * 2 - Math.PI/2),
y: shift + 100 * Math.sin(sec/60 * Math.PI * 2 - Math.PI/2)};
$scope.min = { x: shift + 100 * Math.cos(min/60 * Math.PI * 2 - Math.PI/2),
y: shift + 100 * Math.sin(min/60 * Math.PI * 2 - Math.PI/2)};
$scope.hour = { x: shift + 40 * Math.cos(h/12 * Math.PI * 2 - Math.PI/2),
y: shift + 40* Math.sin(h/12 * Math.PI * 2 - Math.PI/2)};
window.setTimeout(function() {$scope.$apply(update)}, 100);
}
update();
});
</script>
<slide ng-controller="SVGCtrl">
<h1 lang="de">AngularJS Spielereien mit SVG</h1>
<h1 lang="en">AngularJS with SVG</h1>
<h3 lang="de">Nicht nur HTML lässt sich mit Bindings versehen!</h3>
<h3 lang="en">AngularJS bindings are not limited to HTML!</h3>
<pre listing-of="svg"></pre>
{{date | date:'medium'}}
<div id="svg" style="position: relative; left: 350px; top: -30px;">
<svg width="280" height="280" xmlns="http://www.w3.org/2000/svg" version="1.1">
<circle ng-attr-cx="{{circle.x}}" ng-attr-cy="{{circle.y}}" ng-attr-r="{{circle.r}}" style="stroke:#7D7D7D;fill:#EBEBEB"/>
<line ng-attr-x1="{{circle.x}}" ng-attr-y1="{{circle.y}}" ng-attr-x2="{{sec.x}}" ng-attr-y2="{{sec.y}}" style="stroke:#E16969;stroke-width:1" />
<line ng-attr-x1="{{circle.x}}" ng-attr-y1="{{circle.y}}" ng-attr-x2="{{min.x}}" ng-attr-y2="{{min.y}}" style="stroke:#E16969;stroke-width:5" />
<line ng-attr-x1="{{circle.x}}" ng-attr-y1="{{circle.y}}" ng-attr-x2="{{hour.x}}" ng-attr-y2="{{hour.y}}" style="stroke:#E16969;stroke-width:5" />
</svg>
</div>
</slide>
<slide ng-controller="SVGCtrl">
<h1 lang="de">SVG Spielereien mit AngularJS</h1>
<h1 lang="en">SVG with AngularJS </h1>
<pre listing-of="svgController"></pre>
</slide>
<script id="provider">
app.provider('helloProvider', function() {
this.$get = function() {
return {
sayHello: function() {
return "Hello, Provider!"
}
}
}
});
</script>
<slide>
<h1>Provider</h1>
<div lang="de">
Geteilte Daten oder zentrale Funktionalität der Controller werden in singleton Objekte ausgelagert.
<h2>Provider</h2>
<ul>
<li>Provider sind die allgemeinste Form</li>
<li>Können beim Start der App konfiguriert werden</li>
<li>Aufwändige Schreibweise</li>
</ul>
<pre listing-of="provider"></pre>
</div>
<div lang="en">
Shared data can be externalized to singleton objects.
<h2>Provider</h2>
<ul>
<li>Providers are the most general form</li>
<li>They can be configured on startup</li>
<li>Complex syntax</li>
</ul>
<pre listing-of="provider"></pre>
</div>
</slide>
<script id="service">
app.service('helloService', function() {
this.sayHello = function() {
return "Hello, Service! ";
};
});
</script>
<script id="factory">
app.factory('helloFactory', function() {
return {
sayHello: function() {
return "Hello, Factory!";
}
}});
</script>
<script id="value">
app.value('helloValue', "Hello, Value! ");
</script>
<slide>
<h1>Factories, Services, ..</h1>
<div lang="de">Einfachere Schreibweisen für Provider.</div>
<div lang="en">Simple notation for providers.</div>
<h2>Factories</h2>
<pre listing-of="factory"></pre>
<h2>Services</h2>
<pre listing-of="service"></pre>
<h2>Value, Constant</h2>
<pre listing-of="value"></pre>
</slide>
<script id="dependencyInjection1">
app.controller('DependencyInjection1', function($scope, helloProvider, helloValue, helloService, helloFactory) {
console.log(helloValue);
console.log(helloProvider.sayHello());
console.log(helloService.sayHello());
console.log(helloFactory.sayHello());
});
</script>
<script id="dependencyInjection2">
app.controller('DependencyInjection2', ['$scope', 'helloService', 'helloFactory',
function($scope, helloService, helloFactory) {
console.log(helloService.sayHello())
console.log(helloFactory.sayHello());
}]);
</script>
<slide>
<h1>Dependency injection</h1>
<h3 lang="de">Abhängigkeiten in controllern werden 'injected':</h3>
<h3 lang="en">The dependencies of controllers can be 'injected':</h3>
<pre ng-controller="DependencyInjection1" listing-of="dependencyInjection1"></pre>
<h3 lang="de">Alternative Schreibweise:</h3>
<h3 lang="en">Alternative syntax:</h3>
<ul lang="de">
<li>Robust gegen minifying</li>
<li>Namen in Strings eingeschlossen</li>
</ul>
<ul lang="en">
<li>Robust against minifying</li>
<li>The names are enclosed into strings</li>
</ul>
<pre ng-controller="DependencyInjection2" listing-of="dependencyInjection2"></pre>
</slide>
<slide>
<h1 lang="de">Eigene Direktiven</h1>
<h1 lang="en">Custom directives</h1>
<h3 lang="de">AngularJS stellt viele HTML-Erweiterungen (Direktiven) zur Verfügung.</h3>
<h3 lang="en">AngularJS has many HTML extensions (directives) build in.</h3>
<h3 lang="de">Eigene Direktiven lassen sich sehr einfach bauen.</h3>
<h3 lang="en">It is very easy to build your own directives.</h3>
<pre class="prettyprint">
app.directive('name', function () {
return {
restrict: ..
template: ..
replace: ..
templateURL: ..
transclude: ..
link: ..
scope: ..
}
});</pre>
</script>
<h3 lang="de">Über die Parameter der Direktiven sind sehr unterschiedliche Anwendungsfälle abbildbar.</h3>
<h3 lang="en">By using the parameters, different use cases can be achieved.</h3>
</slide>
<slide>
<h1 lang="de">Direktiven - <code>restrict:</code></h1>
<h1 lang="en">Directives - <code>restrict:</code></h1>
<h2 lang="de">Verwendung als Element</h2>
<h2 lang="en">Usage as element</h2>
<pre class="prettyprint">
app.directive('myDirective', function () {
return {
restrict: 'E',
}});</pre>
<pre class="prettyprint"><my-directive ...></my-directive></pre>
<div lang="de" class="small">Vorsicht: <code><my-directive .../></code> funktioniert nicht fehlerfrei!</div>
<div lang="en" class="small">Attention: <code><my-directive .../></code> does not work properly!</div>
<h2 lang="de">Verwendung als Attribut</h2>
<h2 lang="en">Usage as attribute</h2>
<pre class="prettyprint">restrict: 'A',</pre>
<pre class="prettyprint"><div my-directive=".." ...></div> oder <div my-directive></div></pre>
<h2 lang="de">Verwendung als Klasse</h2>
<h2 lang="en">Usage as class</h2>
<pre class="prettyprint">restrict: 'C',</pre>
<pre class="prettyprint"><div class="my-directive" ...></div></pre>
<h3 lang="de">Die Kombination der Optionen geht auch, z.B. <code>restrict: 'AE';</code> </h3>
<h3 lang="en">The combination is also allowed, e.g. <code>restrict: 'AE';</code> </h3>
</slide>
<script id="myButton">
app.directive('myButton', function () {
return {
restrict: 'E',
template: '<button type="button" class="btn">click me</button>',
}});
</script>
<slide>
<h1 lang="de">Direktiven - <code>template:</code></h1>
<h1 lang="en">Directives - <code>template:</code></h1>
<div lang="de">HTML-Templates können auf einfache Weise angegeben werden.</div>
<div lang="en">HTML templates can be used very easy.</div>
<h2>Java Script</h2>
<pre listing-of="myButton"></pre>
<h2 lang="de">Verwendung:</h2> <h2 lang="en">Usage:</h2>
<pre class="prettyprint"><my-button></my-button></pre>
<h2 lang="de">Ergebnis im DOM</h2>
<h2 lang="en">Result within the DOM</h2>
<pre listing-of="button"></pre>
<div lang="de">Mit <code>replace: true</code> würde das umgebende Tag ersetzt werden.</div>
<div lang="en">With <code>replace: true</code>, the surrounding tag would be replaced.</div>
<hr/>
<div id="button">
<my-button></my-button>
</div>
</slide>
<slide>
<h1 lang="de">Direktiven - <code>templateURL:</code></h1>
<h1 lang="en">Direktives - <code>templateURL:</code></h1>
<h3 lang="de">Templates können auch extern definiert werden.</h3>
<h3 lang="en">Templates may also be defined externally.</h3>
<h3 lang="de">Dabei sorgt ein <code>$templateCache</code> dafür, dies nur einmal zu laden.</h3>
<h3 lang="en">The <code>$templateCache</code> is responsible for single loading.</h3>
<br>
<h2 lang="de">Alternative 1: Externes laden von Templates:</h2>
<h2 lang="en">Alternative 1: External template:</h2>
<pre class="prettyprint">templateURL: '/myButton.html'</pre>
<h2 lang="de">Alternative 2: Definition im <code><script/></code>-Tag</h2>
<h2 lang="en">Alternative 2: Definition within <code><script/></code> tag</h2>
<pre class="prettyprint"><script type="text/ng-template" id="/myButton.html">
<button type="button" class="btn">click me</button>
</script></pre>
</slide>
<script id="myButton2">
app.directive('myButton2', function () {
return {
restrict: 'E',
transclude: true,
template: '<button type="button" class="btn">\
<span ng-transclude></span></button>',
}});
</script>
<slide>
<h1 lang="de">Direktiven - <code>transclude:</code></h1>
<h1 lang="en">Directives - <code>transclude:</code></h1>
<div lang="de">Inhalte können auch in ein Template eingeschlossen werden.</div>
<div lang="en">Contents can also be enclosed by a template.</div>
<h2>Java Script</h2>
<pre listing-of="myButton2"></pre>
<h2 lang="de">Verwendung</h2> <h2 lang="en">Usage</h2>
<pre class="prettyprint"><my-button2>That's the <strong>label!</strong><my-button2/></pre>
<hr/>
<div id="transcludeButton">
<my-button2>That's the <strong>label!</strong></my-button2>
</div>
</slide>
<script id="myLinkedButton">
app.directive('myLinkedButton', function () {
return {
restrict: 'E',
template: '<button type="button" class="btn">click me</button>',
link: function (scope, elem, attrs) {
elem.on('click', function() {
alert(attrs.message);
});
}}});
</script>
<slide>
<h1 lang="de">Direktiven - <code>link:</code></h1>
<h1 lang="en">Directives - <code>link:</code></h1>
<h3 lang="de">Mit dem <code>link</code>-Attribut kann beliebiger Code ausführt werden.</h3>
<h3 lang="en">With the <code>link</code> attribute, custom code can be executed.</h3>
<ul lang="de">
<li>Manipulation des Dom</li>
<li>Registrierung von Event-Listenern</li>
<li>Integration mit anderen JS-Libraries</li>
</ul>
<ul lang="en">
<li>DOM manipulation</li>
<li>Registration of event listeners</li>
<li>Integration with other JS libraries</li>
</ul>
<pre listing-of="myLinkedButton"></pre>
<pre class="prettyprint"><my-linked-button message="42, ist the answer!"></my-linked-button></pre>
<div id="button">
<my-linked-button message="42, ist the answer!"/>
</div>
</slide>
<script>
app.controller('SayHelloCtrl', function($scope) {
$scope.sayHello = function() {
alert('Hello ..');
};
});
</script>
<script id="myScopedButton">
app.directive('myScopedButton', function () {
return {
restrict: 'E',
scope: {
myMessage: '@message', // read only mapping
myModel: '=model', // two way binding
myAction: '&action', // function reference
},
template: '<input class="form-control" type="text" ng-model="myModel">\
<button type="button" class="btn" ng-click="myAction()">{{myMessage}}</button>',
}});
</script>
<slide>
<h1 lang="de">Direktiven - <code>scope:</code></h1>
<h1 lang="en">Directives - <code>scope:</code></h1>
<h3 lang="de">Direktiven können einen isolierten Scope besitzen.</h3>
<h3 lang="en">Directives can have an isolated scope.</h3>
<pre listing-of="myScopedButton"></pre>
<pre class="prettyprint"><my-scoped-button message="I'm a button!" model="anyVar" action="sayHello()"></my-scoped-button></pre>
<hr>
<div id="scopedButton" ng-controller="SayHelloCtrl">
<my-scoped-button message="I'm a button!" model="anyVar" action="sayHello()"></my-scoped-button>
<div>anyVar: {{anyVar}}</div>
</div>
</slide>
<div id="viewTemplates">
<script type="text/ng-template" id="/defaultTemplate.html">
<div style="background:grey; height: 150px; "><h3>Default Template {{demoData}}</h3></div>
</script>
<script type="text/ng-template" id="/template1.html">
<div style="background:green; height: 150px;"><h3>Template 1 {{demoData}}</h3></div>
</script>
<script type="text/ng-template" id="/template2.html">
<div style="background:blue; height: 150px;"><h3>Template 2 {{demoData}}</h3></div>
</script>
</div>
<script id="viewConfig">
app.config(function($routeProvider) {
$routeProvider
.when('/template1', {
templateUrl: '/template1.html',
}).when('/template2', {
templateUrl: '/template2.html',
}).otherwise({
templateUrl: '/defaultTemplate.html',
});
});
</script>
<slide>
<h1>Routing - <code>$routeProvider</code></h1>
<h3 lang="de">Seiten können modular aufgebaut werden.</h3>
<h3 lang="en">Pages can be created in a modular fashion.</h3>
<h3 lang="de">Views werden in Templates ausgelagert.</h3>
<h3 lang="en">Views may be externalized in templates.</h3>
<h3 lang="de">Deep-Linking wird unterstützt.</h3>
<h3 lang="en">Deep linking is supported.</h3>
<a class="btn btn-default" href="#defaultTemplate?slide=25">defaultTemplate</a>
<a class="btn btn-default" href="#template1?slide=25">template1</a>
<a class="btn btn-default" href="#template2?slide=25">template2</a>
<br><br>
<div id="viewExample">
<div ng-view></div>
</div>
</slide>
<slide>
<h1>Routing</h1>
<pre listing-of="viewTemplates"></pre>
<pre listing-of="viewConfig"></pre>
<pre class="prettyprint"><div ng-view></div></pre>
</slide>
<script id="uiRouterConfig">
app.config(function($stateProvider) {
$stateProvider
.state('s1', {
url: '/s1',
views: {
'left' : { templateUrl: '/defaultTemplate.html' },
'right' : { templateUrl: '/defaultTemplate.html'}
}
})
.state('s2', {
url: '/s2',
views: {
'left' : { templateUrl: '/template1.html' },
'right' : { templateUrl: '/template2.html'}
}
});
});
</script>
<slide>
<h1>Routing - <code>ui-router</code></h1>
<h3>Sehr mächtiges Routing-Framework (defakto standard)</h3>
<ul>
<li>State basiert (URLs nur optional)</li>
<li>Einbettung mehrerer Views auf der selben Seite</li>
<li>Child States</li>
<li>Controller Initialisierung</li>
</ul>
<h3><a href="https://github.com/angular-ui/ui-router/">https://github.com/angular-ui/ui-router/</a></h3>
<a class="btn btn-default" ui-sref="s1">State 1</a>
<a class="btn btn-default" ui-sref="s2">State 2</a>
<br><br>
<div class="row" id="viewExampleUIRouter">
<div ui-view="left" class="col-md-5">x</div>
<div ui-view="right" class="col-md-5">x</div>
</div>
</slide>
<slide>
<h1>Routing - <code>ui-router</code></h1>
<pre listing-of="uiRouterConfig"></pre>
<pre class="prettyprint"><div ui-view="left">x</div>
<div ui-view="right">x</div></pre>
</slide>
<slide>
<h1>Input Validation</h1>
<div id="css-form">
<form novalidate class="css-form">
<style type="text/css">
#css-form input.ng-invalid.ng-touched {
background-color: #FA787E;
}
#css-form input.ng-valid.ng-touched {
background-color: #78FA89;
}
</style>
<input type="text" class="form-control" ng-model="var1" required placeholder="this is required"/>
<input type="text" class="form-control" ng-model="var2" pattern="^\S+$" placeholder="no spaces here"/>
</form>
</div>
<pre listing-of="css-form"></pre>
</slide>
<script id="httpExampleMocking">
app.run(function($httpBackend) {
var people = [{id: 0, first: 'Arthur', last: 'Dent'},
{id: 1, first: 'Zaphod', last: 'Beeblebrox'}];
$httpBackend.whenGET('/people').respond(people);
$httpBackend.whenGET('/people/1').respond(people[1]);
$httpBackend.expectPOST('/people/1').respond(function(data){return data});
window.setTimeout(function() {
$httpBackend.flush();
}, 1000);
});
</script>
<script id="httpExample">
app.controller('httpExample', function($scope, $http) {
$http.get('/people')
.success(function (result) {
$scope.httpResult = result;
});
});
</script>
<slide ng-controller="httpExample">
<h1 lang="de">Zugriff auf REST Ressourcen</h1>
<h1 lang="en">Accessing REST resources</h1>
<h2><code>$http</code></h2>
<div lang="de">Einfache Api für HTTP-Operationen</div>
<div lang="en">Simple api for HTTP operations</div>
<br><br>
<pre listing-of="httpExample"></pre>
<div>httpResult: <pre>{{httpResult}}</pre></div>
</slide>
<script id="resourceExample">
app.controller('resourceExample', function($scope, $resource) {
var Person = $resource('/people/:id', {id:'@id'});
$scope.person = Person.get({id:1}, function() {
$scope.person.first = 'new Name';
$scope.person.$save();
});
});
</script>
<slide ng-controller="resourceExample">
<h1 lang="de">Zugriff auf REST Ressourcen</h1>
<h1 lang="en">Accessing REST resources</h1>
<h2><code>$resource</code></h2>
<ul lang="de">
<li>Eigenes Modul</li>
<li>Promise-Objekte</li>
<li>Objektorintierten Zugriff, z.B. <code>item.$save</code>, <code>item.$delete</code></li>
</ul>
<ul lang="en">
<li>Special module</li>
<li>Promise objects</li>
<li>Object oriented access, e.g. <code>item.$save</code>, <code>item.$delete</code></li>
</ul>
<pre class="prettyprint"><script src="./lib/angular-resource.min.js"/>
var app = angular.module('presentation', ['ngResource']);</pre>
<pre listing-of="resourceExample"></pre>
<div>person: <pre>{{person}}</pre></div>
</slide>
<slide>
<div lang="de">
<h1>Unit Testing - mocking</h1>
<h3>AngularJS ist für gute Testbarkeit designed!</h3>
<h3>Durch Dependency-Injection lassen sich die Controller gut mocken.</h3>
<h3>angular-mocks.js stellt einige Mocks zum Testen bereit.</h3>
<h2>Beispiel: <code>$httpBackend</code></h2>
</div>
<div lang="en">
<h1>Unit testing - mocking</h1>
<h3>AngularJS is designed for testability!</h3>
<h3>Controllers are mockable through dependency injection.</h3>
<h3>angular-mocks.js brings support for special mock objects.</h3>
<h2>Example: <code>$httpBackend</code></h2>
</div>
<pre listing-of="httpExampleMocking"></pre>
</slide>
<slide>
<h1 lang="de">Unit Testing - Frameworks</h1>
<h1 lang="en">Unit testing - frameworks</h1>
<h2 lang="de">Jasmine: Behavior-Driven Testing Framework</h2>
<h2 lang="en">Jasmine: Behavior driven testing framework</h2>
<pre class="prettyprint">describe("A suite", function() {
beforeEach(function() {
...
});
it("contains spec with an expectation", function() {
expect(true).toBe(true);
});
})</pre>
<h2>Karma: Testrunner</h2>
<ul lang="de">
<li>Einfache Konfiguration</li>
<li>Ständige Ausführung bei <kbd>Ctrl-S</kbd></li>
<li>Gleichzeitiger Test in mehreren Browsern</li>
<li>Mobile Browser können einfach angedockt werden, indem auf die URL navigiert wird.</li>
</ul>
<ul lang="en">
<li>Simple configuration</li>
<li>Instant execution on <kbd>Ctrl-S</kbd></li>