This repository was archived by the owner on Apr 12, 2024. It is now read-only.
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
ngSwitchWhen element eats ngRepeat's child scope #8235
Closed
Description
Scope:
{
foo: 'value',
bars: ['one', 'two'],
}
HTML:
<div ng-switch="foo">
<pre ng-switch-when="value" ng-repeat="bar in bars">
foo = {{foo}}
bar = {{bar}}
$index = {{$index}}
</pre>
</div>
Fiddle: http://jsfiddle.net/y68sy/1/ (http://jsfiddle.net/PqLmp/)
Expected output:
foo = value
bar = one
$index = 0
foo = value
bar = two
$index = 1
Actual output:
foo = value
bar =
$index =
foo = value
bar =
$index =
So the ngRepeat works in the sense that the element is repeated, but the inner scope is wrong; it does not contain the values that ngRepeat puts into it.
This happens because ngSwitch creates a new child scope that inherits from the ngSwitch's scope, not from the ngSwitchWhen's scope:
angular.js/src/ng/directive/ngSwitch.js
Line 169 in e8066c4
I'm not sure if this is expected behaviour, or whether it can be fixed without breaking something else.