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
If any of the scopes should be considered as final destination it can call the method `stopPropagation` of the event object, passed to the callback.
845
-
846
844
```JavaScript
847
845
myModule.controller('MainCtrl', function ($scope) {
848
846
$scope.$on('foo', function () {
@@ -863,31 +861,31 @@ myModule.controller('ChildCtrl', function ($scope) {
863
861
864
862
上記UMLダイアグラムの別々のハンドラーはそれぞれコントローラに注入された別々のスコープです。
865
863
866
-
#### Command
864
+
#### コマンド
867
865
868
-
>In object-oriented programming, the command pattern is a behavioral design pattern in which an object is used to represent and encapsulate all the information needed to call a method at a later time. This information includes the method name, the object that owns the method and values for the method parameters.
When we want to bind our model to the view we use the directives `ng-bind` (for single-way data binding) and `ng-model`(for two-way data binding). For example, if we want each change in the model `foo`to reflect the view we can:
Now each time we change the value of `foo`the inner text of the span will be changed. We can achieve the same effect with more complex AngularJS expressions, like:
Each `$scope`has method called `$watch`. When the AngularJS compiler find the directive `ng-bind`it creates a new watcher of the expression `foo + ' ' + bar | uppercase`, i.e.`$scope.$watch("foo + ' ' + bar | uppercase", function () { /* body */ });`. The callback will be triggered each time the value of the expression change. In the current case the callback will update the value of the span.
886
+
`$scope`は `$watch` と呼ばれるメソッドを持っています。AngularJSコンパイラが `ng-bind`を見つけると、 `foo + ' ' + bar | uppercase` 式のwatcherを生成します。具体的には、`$scope.$watch("foo + ' ' + bar | uppercase", function () { /* body */ });` です。式の値が変わる度に、コールバックが呼ばれます。今回のケースではspanを更新します。
889
887
890
-
Here are the first a couple of lines of the implementation of `$watch`:
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`.
0 commit comments