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

fix(ngRoute): instantiate controller when template is empty #5550

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/ngRoute/directive/ngView.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
23 changes: 23 additions & 0 deletions test/ngRoute/directive/ngViewSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down