diff options
| author | Max | 2012-05-02 18:51:31 +0200 |
|---|---|---|
| committer | Igor Minar | 2012-05-22 14:18:15 -0700 |
| commit | 1d388676e3b97b6171fc498e82545bd437ee6fd1 (patch) | |
| tree | a09e472fc4dc0fb03ce0d5d25160f6a8f3f7ce9d /src/ng/directive/ngRepeat.js | |
| parent | 84542d2431d20de42d6ec27c9d3435dd72dbe2ee (diff) | |
| download | angular.js-1d388676e3b97b6171fc498e82545bd437ee6fd1.tar.bz2 | |
fix(ngRepeat): expose $first, $middle and $last instead of $position
$position marker doesn't work well in cases when we have just one item
in the list because then the item is both the first and last. To solve
this properly we need to expose individual $first and $middle and $last
flags.
BREAKING CHANGE: $position is not exposed in repeater scopes any more
To update, search for $position and replace it with one of $first,
$middle or $last.
Closes #912
Diffstat (limited to 'src/ng/directive/ngRepeat.js')
| -rw-r--r-- | src/ng/directive/ngRepeat.js | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/src/ng/directive/ngRepeat.js b/src/ng/directive/ngRepeat.js index 66464c1b..d5d3a64c 100644 --- a/src/ng/directive/ngRepeat.js +++ b/src/ng/directive/ngRepeat.js @@ -12,10 +12,9 @@ * Special properties are exposed on the local scope of each template instance, including: * * * `$index` – `{number}` – iterator offset of the repeated element (0..length-1) - * * `$position` – `{string}` – position of the repeated element in the iterator. One of: - * * `'first'`, - * * `'middle'` - * * `'last'` + * * `$first` – `{boolean}` – true if the repeated element is first in the iterator. + * * `$middle` – `{boolean}` – true if the repeated element is between the first and last in the iterator. + * * `$last` – `{boolean}` – true if the repeated element is last in the iterator. * * * @element ANY @@ -145,9 +144,10 @@ var ngRepeatDirective = ngDirective({ childScope[valueIdent] = value; if (keyIdent) childScope[keyIdent] = key; childScope.$index = index; - childScope.$position = index === 0 ? - 'first' : - (index == collectionLength - 1 ? 'last' : 'middle'); + + childScope.$first = (index === 0); + childScope.$last = (index === (collectionLength - 1)); + childScope.$middle = !(childScope.$first || childScope.$last); if (!last) { linker(childScope, function(clone){ |
