ngView inside ngSwitch in Angular 1.2rc1
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
The same happens with ngIf and any other directive that alters the DOM. these kind of constructs were working on previous AngularJs versions.
Related to / dupe of #3584 . Try it again with the latest build, that should fix your issues.
http://code.angularjs.org/snapshot/
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.
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!