Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

docs($compile): add more info about optional bindings #16025

Merged
merged 4 commits into from
Jun 5, 2017

Conversation

Narretz
Copy link
Contributor

@Narretz Narretz commented May 31, 2017

This also deletes the incorrect info that a missing attribute
in a non-optional binding will throw.

Closes #15989

What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)
docs

What is the current behavior? (You can also link to an open issue here)
missing / incorrect info

What is the new behavior (if this is a feature change)?
info!

Does this PR introduce a breaking change?
101% not

Please check if the PR fulfills these requirements

Other information:

This also deletes the incorrect info that a missing attribute
in a non-optional binding will throw.

Closes angular#15989
@Narretz Narretz added this to the Backlog milestone May 31, 2017
'localName2': '=attr', // OK
'localName3': '<?attr', // OK
'localName4': ' = attr', // OK
'localName5': 'attr', // ERROR: missing mode @&=
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't mention < 😁

'localName': '@', // OK
'localName2': '=attr', // OK
'localName3': '<?attr', // OK
'localName4': ' = attr', // OK
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why isn't & used as an example?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No idea. It's just a list of examples. * also makes no appearance

@@ -303,16 +303,15 @@
* name. Given `<my-component my-attr="parentModel">` 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:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The suggestion about optional attributes seems correct. Why remove it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've removed it because I centralized the info after the individual descriptions.

@@ -303,16 +303,15 @@
* name. Given `<my-component my-attr="parentModel">` 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
Copy link
Member

@gkalpak gkalpak Jun 2, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This info sounds correct too. Why remove it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is correct: http://plnkr.co/edit/7x6kyfbpWIFCFgTmZb2Z?p=preview
As mentioned below, it will only throw _"upon discovering changes to the local value, since it will be impossible to sync

  • them back to the parent scope"_

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, thanks. This is a more specific case than is handled by the PR.

* 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`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whyyyy??? 😢

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like above, the info about optional attributes is further down. Note that the &, < and @ sections have nothing about optional attributes either.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough.

@@ -347,6 +346,36 @@
* and values into the expression wrapper fn. For example, if the expression is `increment(amount)`
* then we can specify the amount value by calling the `localFn` as `localFn({amount: 22})`.
*
* 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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the the --> the

* 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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

provides --> provide

notoptional: '=',
optional: '=?',
},
bindToController: true,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't you need a controllerAs here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope: #15110
This is actually quite powerful ...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh...you just can't use it on the template. Cool 😃

@Narretz Narretz merged commit e65928e into angular:master Jun 5, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Optional Expression "&?" is not described in docs
3 participants