-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpost.html
executable file
·489 lines (384 loc) · 12.7 KB
/
post.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Real-Time Blog App</title>
<!-- Bootstrap Core CSS -->
<link rel="stylesheet" href="lib/css/bootstrap.min.css">
<link rel="stylesheet" href="lib/css/bootstrap-theme.min.css">
<!-- Custom CSS -->
<link rel="stylesheet" href="css/main.css">
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="//oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="//oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<!-- Navigation -->
<nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
<div class="container">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse"
data-target="#bs-example-navbar-collapse-1">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#/">Demo App</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li class="active">
<a href="#/posts">All Posts</a>
</li>
<li>
<a href="#/admin">Admin</a>
</li>
</ul>
</div>
<!-- /.navbar-collapse -->
</div>
<!-- /.container -->
</nav>
<!-- Page Content -->
<div class="container">
<div class="row">
<!-- Blog Post Content Column -->
<section class="col-md-8">
<!-- Begin Post -->
<article>
<header>
<h1 class="page-header">AngularJS - Controllers</h1>
<p>
<small class="glyphicon glyphicon-user"></small>
by <a href="#">Ilan Cohen</a>
</p>
<p>
<small class="glyphicon glyphicon-time"></small>
Posted on 14 Jan, 2015
</p>
<p>
<b>Tags: </b>
<a href="#" class="label label-default">JavaScript</a>
<a href="#" class="label label-default">AngularJS</a>
</p>
</header>
<hr>
<figure>
<img class="img-responsive" src="data/portfolio/fullsize/1.jpg"
alt="">
</figure>
<hr>
<!-- Post Content -->
<section>
<section>
<h2 id="hid-controllers-extra-topics">Controllers - Extra topics</h2>
</section>
<section>
<h3 id="hid-scope-and-functions-on-scope">$scope and functions on $scope</h3>
<p>The <code>$scope</code> basically serves as the data model.</p>
<p>More info from the Angular website:</p>
<ul>
<li><p>Scopes provide APIs (<code>$watch</code>) to observe model mutations.</p>
</li>
<li><p>Scopes provide APIs (<code>$apply</code>) to propagate any model changes through the system into the view from outside of the “Angular realm” (Controllers, Services, Angular event handlers).</p>
</li>
<li><p>Scopes can be nested to limit access to the properties of application components while providing access to shared model properties. Nested scopes are either <strong>child scopes</strong> or <strong>isolate scopes</strong>. A <strong>child scope</strong> (prototypically) inherits properties from its parent scope. An <strong>isolate scope</strong> does not.</p>
</li>
<li><p>Scopes provide context against which expressions are evaluated. For example, a <code>{{userName}}</code> expression is meaningless, unless it is evaluated against a specific scope which defines the <code>userName</code> property.</p>
</li>
</ul>
</section>
<section>
<h3 id="hid-prototypal-inheritance">Prototypal inheritance</h3>
<p>There is always one root scope, but chlid scopes can exist, and they inherit (prototypically) from their parent scope(s):</p>
<pre><code class="handlebars"><div ng-app="scopeExample">
<div class="show-scope-demo">
<div ng-controller="GreetController">
Hello {{name}}!
</div>
<div ng-controller="ListController">
<ol>
<li ng-repeat="name in names">
{{name}} from {{department}}
</li>
</ol>
</div>
</div>
</div>
</code></pre>
</section>
<section>
<pre><code class="js">angular.module('scopeExample', [])
.controller('GreetController', ['$scope', '$rootScope',
function ($scope, $rootScope) {
$scope.name = 'World';
$rootScope.department = 'Angular';
}
]);
.controller('ListController', ['$scope',
function ($scope) {
$scope.names = ['Igor', 'Misko', 'Vojta'];
}
]);
</code></pre>
</section>
<section>
<pre><code class="css">.show-scope-demo.ng-scope,
.show-scope-demo .ng-scope {
border: 1px solid red;
margin: 3px;
}
</code></pre>
</section>
<section>
<h3 id="hid-passing-by-reference-value">Passing by reference/value</h3>
<p>Remember that there is difference between this:</p>
<pre><code class="js">var str = 'string';
function updateString(strParam) {
strParam = 'other string';
}
updateString(str);
console.log(str);
</code></pre>
<p>And this:</p>
<pre><code class="js">var strObject = {
str: 'string'
};
function updateString(strParam) {
strParam.str = 'other string';
}
updateString(strObject);
console.log(strObject.str);
</code></pre>
</section>
<section>
<p>So too, this:</p>
<pre><code class="handlebars"><div ng-app="scopeExample">
<div ng-controller="ParentController">
<input type="text" ng-model="name">
Hello {{name}}!
<div ng-controller="ChildController">
<input type="text" ng-model="name">
Hello {{name}}!
</div>
</div>
</div>
</code></pre>
<pre><code class="js">angular.module('scopeExample', [])
.controller('ParentController', ['$scope',
function ($scope) {
$scope.name = 'World';
}
])
.controller('ChildController', ['$scope',
function ($scope) { /* ... */ }
]);
</code></pre>
</section>
<section>
<p>is different than this:</p>
<pre><code class="handlebars"><div ng-app="scopeExample">
<div ng-controller="ParentController">
<input type="text" ng-model="data.name">
Hello {{data.name}}!
<div ng-controller="ChildController">
<input type="text" ng-model="name">
Hello {{data.name}}!
</div>
</div>
</div>
</code></pre>
<pre><code class="js">angular.module('scopeExample', [])
.controller('ParentController', ['$scope',
function ($scope) {
$scope.data = {
name: 'World'
};
}
])
.controller('ChildController', ['$scope',
function ($scope) { /* ... */ }
]);
</code></pre>
</section>
<section>
<h3 id="hid-controller-as-syntax">“<code>Controller as</code>“ syntax</h3>
<p><a href="https://docs.angularjs.org/api/ng/directive/ngController">AngularJS.org - ngController</a><br><a href="http://plnkr.co/edit/EndHxw6QcY3dKAZZhEXD?p=preview">Controller As - Example</a></p>
</section>
<section>
<h3 id="hid-built-in-scope-methods">Built-In <code>$scope</code> methods</h3>
<p><strong><code>$watch</code></strong></p>
<blockquote>
<p>Allows listening to variables changes.</p>
</blockquote>
<pre><code class="js">$scope.$watch(
'sampleVar',
// This is the change listener, called when the value returned from the above function changes
function(newValue, oldValue) {
if ( newValue !== oldValue ) {
console.log(newValue, oldValue);
$scope.sampleVar2 = $scope.sampleVar + $scope.sampleVar;
}
},
false
);
</code></pre>
<ul>
<li>Affects performance if used a lot or if doing heavy lifting. Don’t abuse it! </li>
</ul>
</section>
</section>
<!-- End of Post Content -->
</article>
<hr>
<!-- End of Post -->
<!-- Blog Comments -->
<!-- Comments Form -->
<div class="well">
<h4>Leave a Comment:</h4>
<form role="form">
<div class="form-group">
<textarea class="form-control" rows="3"></textarea>
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
</div>
<hr>
<!-- Posted Comments -->
<!-- Comment -->
<div class="media">
<a class="pull-left" href="#">
<img class="media-object" src="http://placehold.it/64x64" alt="">
</a>
<div class="media-body">
<h4 class="media-heading">Some User
<small>14 Jan, 2015</small>
</h4>
<p>Cras sit amet nibh libero, in gravida nulla. Nulla vel metus scelerisque ante sollicitudin commodo. Cras purus odio, vestibulum in vulputate at, tempus viverra turpis. Fusce condimentum nunc ac nisi vulputate fringilla. Donec lacinia congue felis in faucibus.</p>
</div>
</div>
<hr>
<!-- Comment -->
<div class="media">
<a class="pull-left" href="#">
<img class="media-object" src="http://placehold.it/64x64" alt="">
</a>
<div class="media-body">
<h4 class="media-heading">Some User
<small>14 Jan, 2015</small>
</h4>
<p>Cras sit amet nibh libero, in gravida nulla. Nulla vel metus scelerisque ante sollicitudin commodo. Cras purus odio, vestibulum in vulputate at, tempus viverra turpis. Fusce condimentum nunc ac nisi vulputate fringilla. Donec lacinia congue felis in faucibus.</p>
</div>
</div>
</section>
<!-- Blog Sidebar Widgets Column -->
<aside class="col-md-4">
<!-- Blog Search Well -->
<div class="well">
<h4>Search</h4>
<div class="input-group">
<input type="text" class="form-control">
<span class="input-group-btn">
<button class="btn btn-default" type="button">
<span class="glyphicon glyphicon-search"></span>
</button>
</span>
</div>
<!-- /.input-group -->
</div>
<!-- Blog Categories Well -->
<div class="well">
<h3>Filter Posts</h3>
<div class="list-group">
<a href="#" class="list-group-item active">
<span class="badge">8</span>
Show All Posts
</a>
</div>
<h4><small class="glyphicon glyphicon-tag"></small> Category</h4>
<div class="list-group">
<a href="#" class="list-group-item">
<span class="badge">6</span>
JavaScript
</a>
<a href="#" class="list-group-item">
<span class="badge">4</span>
AngularJS
</a>
<a href="#" class="list-group-item">
<span class="badge">2</span>
Grunt
</a>
<a href="#" class="list-group-item">
<span class="badge">2</span>
Tools
</a>
<a href="#" class="list-group-item">
<span class="badge">2</span>
jQuery
</a>
</div>
<h4><small class="glyphicon glyphicon-user"></small> Author</h4>
<div class="list-group">
<a href="#" class="list-group-item">
<span class="badge">4</span>
Ilan Cohen
</a>
<a href="#" class="list-group-item">
<span class="badge">2</span>
Alex Ilyaev
</a>
<a href="#" class="list-group-item">
<span class="badge">2</span>
Amit Choukroun
</a>
</div>
<h4><small class="glyphicon glyphicon-time"></small> Month</h4>
<div class="list-group">
<span href="#" class="list-group-item disabled">
2015
</span>
<a href="#" class="list-group-item">
<span class="badge">4</span>
January
</a>
<span href="#" class="list-group-item disabled">
2014
</span>
<a href="#" class="list-group-item">
<span class="badge">4</span>
December
</a>
</div>
</div>
</aside>
</div>
<!-- /.row -->
<hr>
<!-- Footer -->
<footer>
<div class="row">
<div class="col-lg-12">
<p>Copyright © Swetansh Kumar</p>
</div>
<!-- /.col-lg-12 -->
</div>
<!-- /.row -->
</footer>
</div>
<!-- /.container -->
<!-- Libraries -->
<script src="lib/js/jquery.min.js"></script>
<script src="lib/js/bootstrap.min.js"></script>
<!-- App -->
<script src="app/app.js"></script>
</body>
</html>