From fb0e617c3d86098d79da9639fcaa05c25cf00fa3 Mon Sep 17 00:00:00 2001 From: Martin Staffa Date: Wed, 31 May 2017 20:46:48 +0200 Subject: [PATCH 1/4] docs($compile): add more info about optional bindings This also deletes the incorrect info that a missing attribute in a non-optional binding will throw. Closes #15989 --- docs/content/error/$compile/iscp.ngdoc | 14 +++++----- src/ng/compile.js | 37 +++++++++++++++++++++++--- 2 files changed, 40 insertions(+), 11 deletions(-) diff --git a/docs/content/error/$compile/iscp.ngdoc b/docs/content/error/$compile/iscp.ngdoc index 78f82f2f6c61..4d693fc2d996 100644 --- a/docs/content/error/$compile/iscp.ngdoc +++ b/docs/content/error/$compile/iscp.ngdoc @@ -10,13 +10,13 @@ myModule.directive('directiveName', function factory() { return { ... scope: { - 'attrName': '@', // OK - 'attrName2': '=localName', // OK - 'attrName3': '` and the isolate scope definition `scope: { * localModel: '=myAttr' }`, the property `localModel` on the directive's scope will reflect the * value of `parentModel` on the parent scope. Changes to `parentModel` will be reflected in - * `localModel` and vice versa. Optional attributes should be marked as such with a question mark: - * `=?` or `=?attr`. If the binding expression is non-assignable, or if the attribute isn't - * optional and doesn't exist, an exception ({@link error/$compile/nonassign `$compile:nonassign`}) + * `localModel` and vice versa. If the binding expression is non-assignable, an exception + * ({@link error/$compile/nonassign `$compile:nonassign`}) * will be thrown upon discovering changes to the local value, since it will be impossible to sync * them back to the parent scope. By default, the {@link ng.$rootScope.Scope#$watch `$watch`} * method is used for tracking changes, and the equality check is based on object identity. * However, if an object literal or an array literal is passed as the binding expression, the * equality check is done by value (using the {@link angular.equals} function). It's also possible * to watch the evaluated value shallowly with {@link ng.$rootScope.Scope#$watchCollection - * `$watchCollection`}: use `=*` or `=*attr` (`=*?` or `=*?attr` if the attribute is optional). + * `$watchCollection`}: use `=*` or `=*attr` * * * `<` or ` Date: Fri, 2 Jun 2017 14:36:18 +0200 Subject: [PATCH 2/4] fixup! Better examples for iscp --- docs/content/error/$compile/iscp.ngdoc | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/docs/content/error/$compile/iscp.ngdoc b/docs/content/error/$compile/iscp.ngdoc index 4d693fc2d996..8153e44d4a05 100644 --- a/docs/content/error/$compile/iscp.ngdoc +++ b/docs/content/error/$compile/iscp.ngdoc @@ -11,12 +11,14 @@ myModule.directive('directiveName', function factory() { ... scope: { 'localName': '@', // OK - 'localName2': '=attr', // OK + 'localName2': '&attr', // OK 'localName3': ' Date: Fri, 2 Jun 2017 14:37:52 +0200 Subject: [PATCH 3/4] fixup! typos --- src/ng/compile.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ng/compile.js b/src/ng/compile.js index dd8cbc89b149..c1dfed7bbd7d 100644 --- a/src/ng/compile.js +++ b/src/ng/compile.js @@ -348,8 +348,8 @@ * * All 4 kinds of bindings (`@`, `=`, `<`, and `&`) can be made optional by adding `?` to the expression. * The marker must come before the attribute name. - * See the {@link error/$compile/iscp the Invalid Isolate Scope Definition error} for definition examples. - * This is useful to refine the interface directives provides. + * See the {@link error/$compile/iscp Invalid Isolate Scope Definition error} for definition examples. + * This is useful to refine the interface directives provide. * One subtle difference between optional and non-optional happens **when the binding attribute is not * set**: * - the binding is optional: the property will not be defined From 4d852131277c53c282f1ea5e64539c94095e49de Mon Sep 17 00:00:00 2001 From: Martin Staffa Date: Fri, 2 Jun 2017 17:49:38 +0200 Subject: [PATCH 4/4] re-add info about missing attr with 2way binding --- src/ng/compile.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/ng/compile.js b/src/ng/compile.js index c1dfed7bbd7d..ef2e65ad379d 100644 --- a/src/ng/compile.js +++ b/src/ng/compile.js @@ -303,10 +303,12 @@ * name. Given `` and the isolate scope definition `scope: { * localModel: '=myAttr' }`, the property `localModel` on the directive's scope will reflect the * value of `parentModel` on the parent scope. Changes to `parentModel` will be reflected in - * `localModel` and vice versa. If the binding expression is non-assignable, an exception - * ({@link error/$compile/nonassign `$compile:nonassign`}) - * will be thrown upon discovering changes to the local value, since it will be impossible to sync - * them back to the parent scope. By default, the {@link ng.$rootScope.Scope#$watch `$watch`} + * `localModel` and vice versa. If the binding expression is non-assignable, or if the attribute + * isn't optional and doesn't exist, an exception + * ({@link error/$compile/nonassign `$compile:nonassign`}) will be thrown upon discovering changes + * to the local value, since it will be impossible to sync them back to the parent scope. + * + * By default, the {@link ng.$rootScope.Scope#$watch `$watch`} * method is used for tracking changes, and the equality check is based on object identity. * However, if an object literal or an array literal is passed as the binding expression, the * equality check is done by value (using the {@link angular.equals} function). It's also possible @@ -316,7 +318,7 @@ * * `<` or `` and directive definition of * `scope: { localModel:'