Skip to content

Commit 2ca5e38

Browse files
alex94cpvsavkin
authored andcommitted
fix(upgrade): allow directives with empty template
1 parent b8e69a2 commit 2ca5e38

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

modules/angular2/src/upgrade/upgrade_ng1_adapter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ export class UpgradeNg1ComponentAdapterBuilder {
120120

121121
compileTemplate(compile: angular.ICompileService, templateCache: angular.ITemplateCacheService,
122122
httpBackend: angular.IHttpBackendService): Promise<any> {
123-
if (this.directive.template) {
123+
if (this.directive.template !== undefined) {
124124
this.linkFn = compileHtml(this.directive.template);
125125
} else if (this.directive.templateUrl) {
126126
var url = this.directive.templateUrl;

modules/angular2/test/upgrade/upgrade_spec.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,27 @@ export function main() {
304304
});
305305
}));
306306

307+
it('should support empty template', inject([AsyncTestCompleter], (async) => {
308+
var adapter = new UpgradeAdapter();
309+
var ng1Module = angular.module('ng1', []);
310+
311+
var ng1 = function() { return {template: ''}; };
312+
ng1Module.directive('ng1', ng1);
313+
var Ng2 = Component({
314+
selector: 'ng2',
315+
template: '<ng1></ng1>',
316+
directives: [adapter.upgradeNg1Component('ng1')]
317+
}).Class({constructor: function() {}});
318+
ng1Module.directive('ng2', adapter.downgradeNg2Component(Ng2));
319+
var element = html(`<div><ng2></ng2></div>`);
320+
adapter.bootstrap(element, ['ng1'])
321+
.ready((ref) => {
322+
expect(multiTrim(document.body.textContent)).toEqual('');
323+
ref.dispose();
324+
async.done();
325+
});
326+
}));
327+
307328
it('should support templateUrl fetched from $templateCache',
308329
inject([AsyncTestCompleter], (async) => {
309330
var adapter = new UpgradeAdapter();

0 commit comments

Comments
 (0)