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

Commit

Permalink
fix(ngView): controller not published
Browse files Browse the repository at this point in the history
corrected omitted assignment of controller to the element data object. Without this fix the controller created by ngView is not accessible from the browser debugger.
  • Loading branch information
mhevery committed Mar 19, 2012
1 parent 6c5a05a commit 21e74c2
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/directive/ngView.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ var ngViewDirective = ['$http', '$templateCache', '$route', '$anchorScroll', '$c

lastScope = current.scope = scope.$new();
if (current.controller) {
$controller(current.controller, {$scope: lastScope});
element.contents().
data('$ngControllerController', $controller(current.controller, {$scope: lastScope}));
}

link(lastScope);
Expand Down
29 changes: 29 additions & 0 deletions test/directive/ngViewSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -408,4 +408,33 @@ describe('ng-view', function() {
expect($rootScope.load).toHaveBeenCalledOnce();
});
})


it('should set $scope and $controllerController on the view', function() {
function MyCtrl($scope) {
$scope.state = 'WORKS';
$scope.ctrl = this;
}

module(function($routeProvider) {
$routeProvider.when('/foo', {template: 'tpl.html', controller: MyCtrl});
});

inject(function($templateCache, $location, $rootScope, $route) {
$templateCache.put('tpl.html', [200, '<div>{{state}}</div>', {}]);

$location.url('/foo');
$rootScope.$digest();
expect(element.text()).toEqual('WORKS');

var div = element.find('div');
expect(nodeName_(div.parent())).toEqual('NG:VIEW');

expect(div.scope()).toBe($route.current.scope);
expect(div.scope().hasOwnProperty('state')).toBe(true);
expect(div.scope().state).toEqual('WORKS');

expect(div.controller()).toBe($route.current.scope.ctrl);
});
});
});

0 comments on commit 21e74c2

Please sign in to comment.