|
186 | 186 | * you want to shallow watch for changes (i.e. $watchCollection instead of $watch) you can use
|
187 | 187 | * `=*` or `=*attr` (`=*?` or `=*?attr` if the property is optional).
|
188 | 188 | *
|
189 |
| - * * `<` or `<attr` - set up one-way (one-directional) binding between a local scope property and the |
190 |
| - * parent scope property of name defined via the value of the `attr` attribute. If no `attr` |
191 |
| - * name is specified then the attribute name is assumed to be the same as the local name. |
192 |
| - * Given `<dir my-attr="parentModel">` and directive definition of |
193 |
| - * `scope: { localModel:'<myAttr' }`, then isolate scope property `localModel` will reflect the |
| 189 | + * * `<` or `<attr` - set up a one-way (one-directional) binding between a local scope property and an |
| 190 | + * expression passed via the attribute `attr`. The expression is evaluated in the context of the |
| 191 | + * parent scope. If no `attr` name is specified then the attribute name is assumed to be the same as the |
| 192 | + * local name. You can also make the binding optional by adding `?`: `<?` or `<?attr`. |
| 193 | + * |
| 194 | + * For example, given `<dir my-attr="parentModel">` and directive definition of |
| 195 | + * `scope: { localModel:'<myAttr' }`, then the isolated scope property `localModel` will reflect the |
194 | 196 | * value of `parentModel` on the parent scope. Any changes to `parentModel` will be reflected
|
195 | 197 | * in `localModel`, but changes in `localModel` will not reflect in `parentModel`. There are however
|
196 | 198 | * two caveats:
|
197 | 199 | * 1. one-way binding does not copy the value from the parent to the isolate scope, it simply
|
198 | 200 | * sets the same value. That means if your bound value is an object, changes to its properties
|
199 |
| - * in the isolate scope will be reflected in the parent scope. |
200 |
| - * 2. one-way binding watches changes to the **identity** of the parent value. That is important should |
201 |
| - * you one-way bind an object, and then replace that object in the isolated scope. If you now change |
202 |
| - * a property of the object in your parent scope, the change will not be propagated to the isolated |
203 |
| - * scope, because the identity of the object has not changed. Instead you must assign a new object. |
| 201 | + * in the isolated scope will be reflected in the parent scope (because both reference the same object). |
| 202 | + * 2. one-way binding watches changes to the **identity** of the parent value. That means the |
| 203 | + * {@link ng.$rootScope.Scope#$watch`$watch`} on the parent value only fires if the reference |
| 204 | + * to the value has changed. In most cases, this should not be of concern, but can be important |
| 205 | + * to know if you one-way bind to an object, and then replace that object in the isolated scope. |
| 206 | + * If you now change a property of the object in |
| 207 | + * your parent scope, the change will not be propagated to the isolated scope, because the identity |
| 208 | + * of the object has not changed. Instead you must assign a new object. |
204 | 209 | *
|
205 | 210 | * One-way binding is useful if you do not plan to propagate changes to your isolated scope bindings
|
206 | 211 | * back to the parent. However, it does not make this completely impossible.
|
207 | 212 | *
|
208 |
| - * Same as with bi-directional bindings, you can also use shallow watch for changes (i.e. $watchCollection instead of $watch): |
209 |
| - * `<*` or `<*attr` (`<*?` or `<*?attr` if the property is optional). |
210 |
| - * |
211 | 213 | * * `&` or `&attr` - provides a way to execute an expression in the context of the parent scope.
|
212 | 214 | * If no `attr` name is specified then the attribute name is assumed to be the same as the
|
213 | 215 | * local name. Given `<widget my-attr="count = count + value">` and widget definition of
|
@@ -848,7 +850,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
|
848 | 850 | var EVENT_HANDLER_ATTR_REGEXP = /^(on[a-z]+|formaction)$/;
|
849 | 851 |
|
850 | 852 | function parseIsolateBindings(scope, directiveName, isController) {
|
851 |
| - var LOCAL_REGEXP = /^\s*([@&]|[=<](\*?))(\??)\s*(\w*)\s*$/; |
| 853 | + var LOCAL_REGEXP = /^\s*([@&<]|=(\*?))(\??)\s*(\w*)\s*$/; |
852 | 854 |
|
853 | 855 | var bindings = {};
|
854 | 856 |
|
@@ -3064,15 +3066,10 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
|
3064 | 3066 |
|
3065 | 3067 | destination[scopeName] = parentGet(scope);
|
3066 | 3068 |
|
3067 |
| - if (definition.collection) { |
3068 |
| - removeWatch = scope.$watchCollection(parentGet, function parentCollectionValueWatchAction(newParentValue) { |
3069 |
| - destination[scopeName] = newParentValue; |
3070 |
| - }); |
3071 |
| - } else { |
3072 |
| - removeWatch = scope.$watch(parentGet, function parentValueWatchAction(newParentValue) { |
3073 |
| - destination[scopeName] = newParentValue; |
3074 |
| - }, parentGet.literal); |
3075 |
| - } |
| 3069 | + removeWatch = scope.$watch(parentGet, function parentValueWatchAction(newParentValue) { |
| 3070 | + destination[scopeName] = newParentValue; |
| 3071 | + }, parentGet.literal); |
| 3072 | + |
3076 | 3073 | removeWatchCollection.push(removeWatch);
|
3077 | 3074 | break;
|
3078 | 3075 |
|
|
0 commit comments