Skip to content

Hammer.js and Template interaction causes NPE #723

@mhevery

Description

@mhevery

Assume this template

<ul>
  <li !if="exp" (tap)="doSomething()"></li>
<ul>

Here the li will get turned into:

<template>
  <li !if="exp" (tap)="doSomething()"></li>
</template>

Once the View of the if gets instantiated it will attempt to register a tap event on Hammer. The issue is that the element is a clone of the <template> and is not yet inserted into the main document for rendering. Hammer will than try to register a listener on the wrong document, which is null.

(See hammer.js)

function getWindowForElement(element) {
    var doc = element.ownerDocument;
    return (doc.defaultView || doc.parentWindow);
}

The issue is that the doc.defaultView is null since the ownerDocument is that of the template and not of the main document.

Proposed Fix

Use document.importNode(element, true) instead of element.cloneNode(true)

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions