diff --git a/src/TemplateBinding.js b/src/TemplateBinding.js index f2851bf..8d32284 100644 --- a/src/TemplateBinding.js +++ b/src/TemplateBinding.js @@ -1006,13 +1006,14 @@ return; var template = this.templateElement_; + var delegate = template.bindingDelegate; + if (!template.parentNode || !template.ownerDocument.defaultView) { this.close(); return; } if (this.instanceModelFn_ === undefined) { - var delegate = template.bindingDelegate; if (delegate && typeof delegate.prepareInstanceModel === 'function') this.instanceModelFn_ = delegate.prepareInstanceModel(template); if (typeof this.instanceModelFn_ !== 'function') diff --git a/tests/tests.js b/tests/tests.js index b41e81c..6672c42 100644 --- a/tests/tests.js +++ b/tests/tests.js @@ -1846,8 +1846,43 @@ suite('Template Instantiation', function() { assert.strictEqual(1, template3.content.childNodes.length); assert.strictEqual('Hello', template3.content.firstChild.textContent); }); -}); + test('issue-285', function() { + var div = createTestHtml( + ''); + + var template = div.firstChild; + + var model = { + show: true, + items: [1] + }; + + div.appendChild(template.createInstance(model, { + prepareInstanceModel: function(template) { + if (template.id == 'del') { + return function(val) { + return val*2; + }; + } + } + })); + + Platform.performMicrotaskCheckpoint(); + assert.equal('2', template.nextSibling.nextSibling.nextSibling.textContent); + model.show = false; + Platform.performMicrotaskCheckpoint(); + model.show = true; + Platform.performMicrotaskCheckpoint(); + assert.equal('2', template.nextSibling.nextSibling.nextSibling.textContent); + }); +}); suite('Binding Delegate API', function() {