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: README.md
+25-23Lines changed: 25 additions & 23 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -14,7 +14,7 @@
14
14
*[Directives](#directives)
15
15
*[Filters](#filters)
16
16
*[Services](#services)
17
-
*[Angular 2 overview](#angular-2-overview)
17
+
*[Angular 2 Overview](#angular-2-overview)
18
18
*[Components](#components)
19
19
*[Services](#services)
20
20
*[Dependency Injection](#dependency-injection)
@@ -270,13 +270,15 @@ function MyCtrl(Developer) {
270
270
}
271
271
```
272
272
273
+
## Angular 2 Overview
274
+
273
275
## AngularJS in Patterns
274
276
275
-
In the next a couple of sections, we are going to take a look how the traditional design and architectural patterns are composed in the AngularJS components.
277
+
In the next a couple of sections, we are going to take a look at how the traditional design and architectural patterns are composed in the AngularJS components. The following chapter is devided in two parts - AngularJS 1.x and Angular 2. In the corresponding chapters the patterns will be put in the appropriate context.
276
278
277
-
In the last chapter we are going to take a look at some architectural patterns, which are frequently used in the development of Single-Page Applications with (but not limited to) AngularJS.
279
+
### AngularJS 1.x
278
280
279
-
### Services
281
+
####Services
280
282
281
283
<!-- include singleton -->
282
284
@@ -324,7 +326,7 @@ This way the services are actually singletons but not implemented through the Si
324
326
325
327
For further discussion on this topic Misko Hevery's [article](http://googletesting.blogspot.com/2008/05/tott-using-dependancy-injection-to.html) in the Google Testing blog could be considered.
326
328
327
-
#### Factory Method
329
+
#####Factory Method
328
330
329
331
<!-- include factory-method -->
330
332
@@ -412,7 +414,7 @@ There are a few benefits of using the factory method pattern in this case, becau
412
414
- Resolving all the dependencies required by the component
413
415
- The number of instances the given component is allowed to have (for services and filters only a single one but multiple for the controllers)
414
416
415
-
#### Decorator
417
+
#####Decorator
416
418
417
419
<!-- include decorator -->
418
420
@@ -450,7 +452,7 @@ We decorate the service by overriding its method `bar`. The actual decoration is
450
452
451
453
Using this pattern is especially useful when we need to modify the functionality of third party services. In cases when multiple similar decorations are required (like performance measurement of multiple methods, authorization, logging, etc.), we may have a lot of duplications and violate the DRY principle. In such cases it is useful to use [aspect-oriented programming](http://en.wikipedia.org/wiki/Aspect-oriented_programming). The only AOP framework for AngularJS I'm aware of could be found at [github.com/mgechev/angular-aop](https://github.com/mgechev/angular-aop).
452
454
453
-
#### Facade
455
+
#####Facade
454
456
455
457
<!-- include facade -->
456
458
@@ -499,7 +501,7 @@ The second option provides pre-configured version, which creates a HTTP POST req
499
501
500
502
Even higher level of abstraction is being created by `$resource`, which is build over the `$http` service. We will take a further look at this service in [Active Record](#active-record) and [Proxy](#proxy) sections.
501
503
502
-
#### Proxy
504
+
#####Proxy
503
505
504
506
<!-- include proxy -->
505
507
@@ -535,7 +537,7 @@ function MainCtrl($scope, $resource) {
535
537
```
536
538
Initially when the snippet above executes, the property `user` of the `$scope` object will be with value an empty object (`{}`), which means that `user.name` will be undefined and nothing will be rendered. Internally AngularJS will keep reference to this empty object. Once the server returns response for the get request, AngularJS will populate the object with the data, received from the server. During the next `$digest` loop AngularJS will detect change in `$scope.user`, which will lead to update of the view.
537
539
538
-
#### Active Record
540
+
#####Active Record
539
541
540
542
<!-- include active-record -->
541
543
@@ -576,7 +578,7 @@ Since Martin Fowler states that
576
578
577
579
`$resource` does not implements exactly the Active Record pattern, since it communicates with RESTful service instead of the database. Anyway, we can consider it as "Active Record like RESTful communication".
@@ -650,7 +652,7 @@ From the first example we can note that the whole DOM tree is a composition of e
650
652
651
653
In the second, JavaScript, example we see that the `template` property of the directive, contains markup with `ng-transclude` directive inside it. So this means that inside the directive `zippy` we have another directive called `ng-transclude`, i.e. composition of directives. Theoretically we can nest the components infinitely until we reach a leaf node.
652
654
653
-
### Interpreter
655
+
####Interpreter
654
656
655
657
<!-- include interpreter -->
656
658
@@ -718,7 +720,7 @@ Few sample AngularJS expressions are:
We can think of the `watcher` object as a command. The expression of the command is being evaluated on each [`"$digest"`](https://docs.angularjs.org/api/ng/type/$rootScope.Scope#$digest) loop. Once AngularJS detects change in the expression, it invokes the `listener` function. The `watcher` command encapsulates the whole information required for watching given expression and delegates the execution of the command to the `listener` (the actual receiver). We can think of the `$scope` as the command's `Client` and the `$digest` loop as the command's `Invoker`.
885
887
886
-
### Controllers
888
+
#### Controllers
887
889
888
-
#### Page Controller
890
+
##### Page Controller
889
891
890
892
<!-- include page-controller -->
891
893
@@ -933,9 +935,9 @@ This example aims to illustrates the most trivial way to reuse logic by using a
933
935
934
936
The `ChildCtrl` is responsible for handling actions such as clicking the button with label `"Click"` and exposing the model to the view, by attaching it to the scope.
935
937
936
-
### Others
938
+
#### Others
937
939
938
-
#### Module Pattern
940
+
##### Module Pattern
939
941
940
942
<!-- include module-pattern -->
941
943
@@ -962,7 +964,7 @@ app.factory('foo', function () {
962
964
963
965
Once we want to inject `foo` inside any other component we won't be able to use the private methods, but only the public ones. This solution is extremely powerful especially when one is building a reusable library.
0 commit comments