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.

ngView inside ngSwitch causes $routeProvider to load controller twice. #5754

@worldspawn

Description

@worldspawn

Hi i have the following markup:

        <div class="main-content" ng-switch on="errorState" ng-cloak>
            <div class="container" ng-switch-when="403">
                <div ng-include="'/public/views/error/index.html'"></div>
            </div>
            <div class="container" ng-switch-default>
                <div ng-view></div>
            </div>

            <footer class="site-footer">
                <div class="container">
                    <ul>
                        <li ng-repeat="node in menuNodes | filter: {showInFooter:true}"><a href="{{node.path}}">{{node.menuTitle || node.title }}</a></li>
                    </ul>
                </div>
            </footer>
        </div>

And a route (but this applies to all my routes)

$routeProvider.when('/roundtables', {
        templateUrl: '/public/views/roundtable/index.html',
        controller: 'roundtableController'
    });

When a browse directly to (meaning i type into the address bar) /roundtables' theroundtableController` is initialised twice.

If i enter the url /roundtables/ (has trailing slash) the controller is initialised only once.

If i take my ng-view and put it outside of the ng-switch i do not get this behaviour.

All angular files loaded with:

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.6/angular.min.js"></script>
        <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.6/angular-route.min.js"></script>
        <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.6/angular-resource.min.js"></script>
        <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.6/angular-sanitize.min.js"></script>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions