diff --git a/src/ngRoute/directive/ngView.js b/src/ngRoute/directive/ngView.js index b12529444715..0ae1c4fc753b 100644 --- a/src/ngRoute/directive/ngView.js +++ b/src/ngRoute/directive/ngView.js @@ -199,7 +199,7 @@ function ngViewFactory( $route, $anchorScroll, $animate) { var locals = $route.current && $route.current.locals, template = locals && locals.$template; - if (template) { + if (angular.isDefined(template)) { var newScope = scope.$new(); var current = $route.current; diff --git a/test/ngRoute/directive/ngViewSpec.js b/test/ngRoute/directive/ngViewSpec.js index a8d1f4596e6a..cb3455e68a51 100644 --- a/test/ngRoute/directive/ngViewSpec.js +++ b/test/ngRoute/directive/ngViewSpec.js @@ -56,6 +56,29 @@ describe('ngView', function() { }); + it('should instantiate controller for empty template', function() { + var log = [], controllerScope, + Ctrl = function($scope) { + controllerScope = $scope; + log.push('ctrl-init'); + }; + + module(function($routeProvider) { + $routeProvider.when('/some', {templateUrl: '/tpl.html', controller: Ctrl}); + }); + + inject(function($route, $rootScope, $templateCache, $location) { + $templateCache.put('/tpl.html', [200, '', {}]); + $location.path('/some'); + $rootScope.$digest(); + + expect(controllerScope.$parent).toBe($rootScope); + expect(controllerScope).toBe($route.current.scope); + expect(log).toEqual(['ctrl-init']); + }); + }); + + it('should instantiate controller with an alias', function() { var log = [], controllerScope, Ctrl = function($scope) {