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
The AngularJS controllers are JavaScript functions, which help handling the user interactions with the web application (for example mouse events, keyboard events, etc.), by attaching methods to the *scope*. All required external, for the controllers, components are provided through the Dependency Injection mechanism of AngularJS. The controllers are also responsible for providing the *model* to the partials by attaching data to the *scope*. We can think of this data as *view model*.
109
+
AngularJS 控制器是 JavaScript 函数,它通过在“scope”上附加处理方法的方式,来处理用户与 web 应用间的交互(比如鼠标事件,键盘事件等等)。
@@ -120,20 +122,21 @@ function MyController($scope) {
120
122
}
121
123
```
122
124
123
-
For example, if we wire the sample controller above with the partial provided in the previous section the user will be able to interact with the application in few different ways.
125
+
举个例子,如果我们把上面的示例控制器和先前给出的局部模板放到一块,用户可能通过以下几种方式交互:
124
126
125
-
1.Change the value of `foo`by typing in the input box. This will immediately reflect the value of `foo`because of the two-way data binding.
126
-
2.Change the value of `foo` by clicking the button, which will be labeled `Click me to change foo!`.
All the custom elements, attributes, comments or classes could be recognized as AngularJS *directives* if they are previously defined as ones.
130
+
所有自定义元素、属性、注释或 class 都会被当做 AngularJS *指令*(directives),前提是指令已经定义。
129
131
130
132
### Scope
131
133
132
-
In AngularJS scope is a JavaScript object, which is exposed to the partials. The scope could contain different properties - primitives, objects or methods. All methods attached to the scope could be invoked by evaluation of AngularJS expression inside the partials associated with the given scope or direct call of the method by any component, which keeps reference to the scope. By using appropriate *directives*, the data attached to the scope could be binded to the view in such a way that each change in the partial will reflect a scope property and each change of a scope property will reflect the partial.
Another important characteristics of the scopes of any AngularJS application is that they are connected into a prototypical chain (except scopes, which are explicitly stated as *isolated*). This way any child scope will be able to invoke methods of its parents since they are properties of its direct or indirect prototype.
Scope inheritance is illustrated in the following example:
139
+
Scope 继承可以用下面的例子描述:
137
140
138
141
```HTML
139
142
<divng-controller="BaseCtrl">
@@ -158,7 +161,7 @@ function ChildCtrl($scope) {
158
161
}
159
162
```
160
163
161
-
With `div#child`is associated `ChildCtrl`but since the scope injected inside `ChildCtrl`inherits prototypically from its parent scope (i.e. the one injected inside `BaseCtrl`) the method `foo`is accessible by`button#parent-method`.
0 commit comments