Skip to content
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
@ttencate

Description

@ttencate

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:

var selectedScope = scope.$new();

I'm not sure if this is expected behaviour, or whether it can be fixed without breaking something else.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions