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

Leading/trailing whitespace in directive attributes with scope "&" is lost #14539

Closed
ChristopherBrix opened this issue Apr 29, 2016 · 2 comments

Comments

@ChristopherBrix
Copy link

When I create a directive with an attribute which scope is defined with &, leading and trailing whitespaces are lost (fiddle).

While it can be circumvented by creating a variable and passing the evaluated variable as the value (using attribute={{variable}}, see the fiddle), this looks like a bug to me.

The fiddle uses Angular 1.4.9, but it's still present in the current snapshot v1.5.6-build.4785+sha.707664a

@gkalpak
Copy link
Member

gkalpak commented Apr 29, 2016

So, this has been the case since v1.0.0-rc.2 (8af4fde). I labelled this as a bug, but it could be expected behavior as well.

This is been around for so long, that I am not sure it is worth changing now.
If anyone wants to submit a PR, the problem "starts" at compile.js#L1887.

@Narretz
Copy link
Contributor

Narretz commented Apr 29, 2016

I think this is similar to #11859

Narretz pushed a commit to Narretz/angular.js that referenced this issue Jun 8, 2016
BREAKING CHANGE:

White-space in attributes is no longer trimmed automatically. This includes leading and trailing
whitespace, and attributes that are purely white-space.

This allows developers to use white-space in their attributes, for example as value for
input[type=radio], as a separator in ngList, or as a value in any custom directive binding.

To migrate, attributes that require trimming must now be trimmed manually.

A common cases where stray white-space can cause problems is when
attribute values are compared, for example in an $observer:

```
$attrs.$observe('myAttr', function(newVal) {
  if (newVal === 'false') ...
});
```

Note that `$parse` trims expressions automatically, so attributes with expressions (e.g. directive
bindings) are unlikely to be affected by stray white-space.

Fixes angular#5513
Fixes angular#14539
Closes angular#5597

ngList test
Narretz pushed a commit to Narretz/angular.js that referenced this issue Jun 8, 2016
BREAKING CHANGE:

White-space in attributes is no longer trimmed automatically. This includes leading and trailing
whitespace, and attributes that are purely white-space.

This allows developers to use white-space in their attributes, for example as value for
input[type=radio], as a separator in ngList, or as a value in any custom directive binding.

To migrate, attributes that require trimming must now be trimmed manually.

A common cases where stray white-space can cause problems is when
attribute values are compared, for example in an $observer:

```
$attrs.$observe('myAttr', function(newVal) {
  if (newVal === 'false') ...
});
```

Note that `$parse` trims expressions automatically, so attributes with expressions (e.g. directive
bindings) are unlikely to be affected by stray white-space.

Fixes angular#5513
Fixes angular#14539
Closes angular#5597

ngList test
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants