mirror of
https://github.com/zhigang1992/angular.js.git
synced 2026-04-24 03:55:49 +08:00
fix(ngRoute): instantiate controller when template is empty
Before this change, $route controllers are not instantiated if the template is falsy, which includes the empty string. This change tests if the template is not undefined, rather than just falsy, in order to ensure that templates are instantiated even when the template is empty, which people may have some reason to do. This "bug" was reported in http://robb.weblaws.org/2013/06/21/angularjs-vs-emberjs/, as a "gotcha" for AngularJS / ngRoute. Closes #5550
This commit is contained in:
committed by
Igor Minar
parent
056c849352
commit
498365f219
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user