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

ngView inside ngSwitch in Angular 1.2rc1 #3719

Closed
AGiorgetti opened this issue Aug 23, 2013 · 4 comments
Closed

ngView inside ngSwitch in Angular 1.2rc1 #3719

AGiorgetti opened this issue Aug 23, 2013 · 4 comments

Comments

@AGiorgetti
Copy link

If I put an ngView directive inside an ngSwitch I do not see the correct template rendered: all I get, inspecting the html, is an empty comment.

If I check with the debugger all the code that process the ngView directive seem to run correctly, I just don't get the template inserted in the DOM.

To reproduce the issue you can use this code:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>ngView inside ngSwitch test</title>
</head>
<body data-ng-controller="mainCtrl">
    Page Content
    <div data-ng-switch="routeData">
        <div data-ng-switch-when="1">
            View 1
            <div data-ng-view=""></div>
        </div>
    </div>
    <br />
    View 2
    <div data-ng-view=""></div>
    <script src="../../Scripts/angular.js"></script>
    <script src="../../Scripts/angular-route.js"></script>
    <script>
        angular.element(document).ready(function () {
            var app = angular.module('myApp', ['ngRoute']);
            app.config(['$routeProvider', function ($routeProvider) {
                $routeProvider
                    .when('/test', { templateUrl: 'ngviewtemplate.html', controller: 'viewController', data: {} })
                    .when('/test2', { template: '<h1>{{data}}</h1>', controller: 'viewController', data: {} });
            }]);

            app.controller('mainCtrl', function ($scope) {
                $scope.routeData = '1';
            });

            app.controller('viewController', function ($scope) {
                $scope.data = 'test data';
            });

            angular.bootstrap(document, ['myApp']);
        });
    </script>
</body>
</html>

and for the template file use:

<div>
    Template Content
    <h1>{{data}}</h1>
</div>

any idea on how to solve the thing?

Thanks all for your help.
Alessandro

@AGiorgetti
Copy link
Author

The same happens with ngIf and any other directive that alters the DOM. these kind of constructs were working on previous AngularJs versions.

@kevin-smets
Copy link

Related to / dupe of #3584 . Try it again with the latest build, that should fix your issues.

http://code.angularjs.org/snapshot/

@AGiorgetti
Copy link
Author

Yes I just saw some changes on the new ngView were reverted, using the new code everything works again, thanks. I'll wait for next RC to update my projects.

@btford
Copy link
Contributor

btford commented Dec 9, 2013

There have since been several changes to Angular's compiler related to this. I assume this should be working now (in ~1.2.4), but let me know if that's not the case and I'll gladly re-open it. Thanks!

@btford btford closed this as completed Dec 9, 2013
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants