2016-03-11 22 views
1

我使用聚合物1.0,並在註冊方法和調用方法時遇到問題。它在Chrome中運行良好,但在Firefox中我收到以下錯誤消息:dom-bind錯誤:偵聽器方法未定義

[dom-bind::_createEventHandler]: listener method `_onCircleClick` not defined 

以下代碼部分包含在其他聚合物元素內。

<template id="main" is="dom-bind"> 
    <neon-animated-pages id="pages" selected="0"> 
    <main-page on-circle-click="_onCircleClick"></main-page> 
    <detail-page on-click="_onPageClick"></detail-page> 
    </neon-animated-pages> 
</template> 
<script> 
    var template = document.querySelector('#main'); 

    template._onCircleClick = function (event) { 
    this.$.pages.selected = 1; 
    }; 

    template._onPageClick = function (event) { 
    this.$.pages.selected = 0; 
    }; 
</script> 

我不知道爲什麼它不起作用的Firefox。有任何想法嗎?

+0

你加載webcomponents.js填充工具的? –

+0

是的,我正在加載'' 但它沒有幫助 – Christian

+0

附註:docs建議使用'on-tap'比'on-click':https://www.polymer-project.org/1.0/docs/devguide/events.html#gestures –

回答

1

如果這是一個自定義標籤,我認爲你不應該使用dom綁定。

而不是使用template._onCircleClick = function() 嘗試_onCircleClick: function()

(function(){ 
     Polymer({ 
      is: "tag-name", 
      properties: { 
      }, 
      _onCircleClick: function() { 
       this.$.pages.selected = 1; 
      }, 
     }); 
    })(); 
+0

非常感謝!它現在工作正常 – Christian