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

fix($compile): set attribute value even if ngAttr* contains no interpolation #15149

Closed

Conversation

gkalpak
Copy link
Member

@gkalpak gkalpak commented Sep 16, 2016

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

What is the current behavior? (You can also link to an open issue here)
Previoulsy, when the value of an ngAttrXyz attribute did not contain any interpolation, then the xyz attribute was never set.
See #15133.

Does this PR introduce a breaking change?
No.

Please check if the PR fulfills these requirements

Other information:
BTW, this commit adds a negligible overhead (since we have to set up a one-time watcher for
example), but it is justifiable for someone that is using ngAttrXyz (instead of xyz directly).

Fixes #15133.

…rpolation

Previoulsy, when the value of an `ngAttrXyz` attribute did not contain any interpolation, then the
`xyz` attribute was never set.

BTW, this commit adds a negligible overhead (since we have to set up a one-time watcher for
example), but it is justifiable for someone that is using `ngAttrXyz` (instead of `xyz` directly).

Fixes angular#15133
@Narretz
Copy link
Contributor

Narretz commented Sep 23, 2016

LGTM,
although I can't really see that with this change there's any possibility of adding an attribute interpolate directive that does not have an embedded expression. If you are using interpolation markers, then everything inside is treated as an expression, and only if you use interpolation markers a interpolation directive is added. That means you technically don't have to require mustHaveExpression, because it'll always have one, no?

@gkalpak
Copy link
Member Author

gkalpak commented Sep 25, 2016

Not really (if I understand correctly what you are asking 😁).

We call addAttrInterpolateDirective(...) for every attribute and it is addAttrInterpolateDirective's job to find out whether there is an interpolation and an actual directive needs to be added.

In order to do this, it passed the string value to $interpolate and checks whether interpolate return something. (With mustHaveExpression true, $interpolate will only return "something" - i.e. an interpolation function - if there is something to interpolate.)

In case of constant values in ngAttrXyz, $interpolate would return undefined (because of mustHaveExpression) and no directive would be added, which means the xyz attribute would not be set.

With this change though, since mustHaveExpression will be false for ngAttrXyz, $interpolate will return something (even if there is not expression in the string value) and a directive will be set up, which will in turn set the xyz property.

(And because $interpolate will return a special interpolation function it has for constants, the created watcher will be unregistered after the first time it is triggered, so there is no extra cost - except for the initial directive+watcher setup cost, of course.)

@gkalpak gkalpak closed this in 3fe3da8 Sep 25, 2016
gkalpak added a commit that referenced this pull request Sep 25, 2016
…rpolation

Previoulsy, when the value of an `ngAttrXyz` attribute did not contain any interpolation, then the
`xyz` attribute was never set.

BTW, this commit adds a negligible overhead (since we have to set up a one-time watcher for
example), but it is justifiable for someone that is using `ngAttrXyz` (instead of `xyz` directly).

(There is also some irrelevant refactoring to remove unnecessary dependencies from tests.)

Fixes #15133

Closes #15149
@gkalpak gkalpak deleted the fix-ngAttr-non-interpolated-value branch October 5, 2016 11:53
petebacondarwin pushed a commit to petebacondarwin/angular.js that referenced this pull request Nov 21, 2016
…rpolation

Previoulsy, when the value of an `ngAttrXyz` attribute did not contain any interpolation, then the
`xyz` attribute was never set.

BTW, this commit adds a negligible overhead (since we have to set up a one-time watcher for
example), but it is justifiable for someone that is using `ngAttrXyz` (instead of `xyz` directly).

(There is also some irrelevant refactoring to remove unnecessary dependencies from tests.)

Fixes angular#15133

Closes angular#15149
petebacondarwin pushed a commit to petebacondarwin/angular.js that referenced this pull request Nov 21, 2016
…rpolation

Previoulsy, when the value of an `ngAttrXyz` attribute did not contain any interpolation, then the
`xyz` attribute was never set.

BTW, this commit adds a negligible overhead (since we have to set up a one-time watcher for
example), but it is justifiable for someone that is using `ngAttrXyz` (instead of `xyz` directly).

(There is also some irrelevant refactoring to remove unnecessary dependencies from tests.)

Fixes angular#15133

Closes angular#15149
petebacondarwin pushed a commit to petebacondarwin/angular.js that referenced this pull request Nov 21, 2016
…rpolation

Previoulsy, when the value of an `ngAttrXyz` attribute did not contain any interpolation, then the
`xyz` attribute was never set.

BTW, this commit adds a negligible overhead (since we have to set up a one-time watcher for
example), but it is justifiable for someone that is using `ngAttrXyz` (instead of `xyz` directly).

(There is also some irrelevant refactoring to remove unnecessary dependencies from tests.)

Fixes angular#15133

Closes angular#15149
petebacondarwin pushed a commit to petebacondarwin/angular.js that referenced this pull request Nov 21, 2016
…rpolation

Previoulsy, when the value of an `ngAttrXyz` attribute did not contain any interpolation, then the
`xyz` attribute was never set.

BTW, this commit adds a negligible overhead (since we have to set up a one-time watcher for
example), but it is justifiable for someone that is using `ngAttrXyz` (instead of `xyz` directly).

(There is also some irrelevant refactoring to remove unnecessary dependencies from tests.)

Fixes angular#15133

Closes angular#15149
petebacondarwin pushed a commit to petebacondarwin/angular.js that referenced this pull request Nov 21, 2016
…rpolation

Previoulsy, when the value of an `ngAttrXyz` attribute did not contain any interpolation, then the
`xyz` attribute was never set.

BTW, this commit adds a negligible overhead (since we have to set up a one-time watcher for
example), but it is justifiable for someone that is using `ngAttrXyz` (instead of `xyz` directly).

(There is also some irrelevant refactoring to remove unnecessary dependencies from tests.)

Fixes angular#15133

Closes angular#15149
petebacondarwin pushed a commit that referenced this pull request Nov 23, 2016
…rpolation

Previoulsy, when the value of an `ngAttrXyz` attribute did not contain any interpolation, then the
`xyz` attribute was never set.

BTW, this commit adds a negligible overhead (since we have to set up a one-time watcher for
example), but it is justifiable for someone that is using `ngAttrXyz` (instead of `xyz` directly).

(There is also some irrelevant refactoring to remove unnecessary dependencies from tests.)

Fixes #15133

Closes #15149
petebacondarwin pushed a commit that referenced this pull request Nov 24, 2016
…rpolation

Previoulsy, when the value of an `ngAttrXyz` attribute did not contain any interpolation, then the
`xyz` attribute was never set.

BTW, this commit adds a negligible overhead (since we have to set up a one-time watcher for
example), but it is justifiable for someone that is using `ngAttrXyz` (instead of `xyz` directly).

(There is also some irrelevant refactoring to remove unnecessary dependencies from tests.)

Fixes #15133

Closes #15149
ellimist pushed a commit to ellimist/angular.js that referenced this pull request Mar 15, 2017
…rpolation

Previoulsy, when the value of an `ngAttrXyz` attribute did not contain any interpolation, then the
`xyz` attribute was never set.

BTW, this commit adds a negligible overhead (since we have to set up a one-time watcher for
example), but it is justifiable for someone that is using `ngAttrXyz` (instead of `xyz` directly).

(There is also some irrelevant refactoring to remove unnecessary dependencies from tests.)

Fixes angular#15133

Closes angular#15149
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.

$interpolate 'allOrNothing' ignores empty case
3 participants