聚合物3纸张对话框:未捕获的TypeError:无法读取未定义的属性“对话框”

时间:2019-03-01 05:14:00

标签: javascript polymer

怎么了?请告诉我 我试图从按钮运行-它不起作用。也许没有连接?但日志中没有任何内容

import '@polymer/paper-dialog/paper-dialog.js';
import { html } from '@polymer/polymer/lib/utils/html-tag.js';
import { PolymerElement } from '@polymer/polymer/polymer-element.js';
class BuildingForm extends PolymerElement {
  static get template() {
    return html`
      <paper-dialog id="dialog" with-backdrop="">
        <h2>header</h2>
        <div>Dialog body</div>
      </paper-dialog>
    `;
  }
  ready(){
    window.addEventListener('openBuildingForm', e => {
        this.openDialog();
    });
  }
  static get properties() {
    return {
      BuildingFormHeader: String,
    }
  }
  openDialog(){
    this.$.dialog.toggle();
  }
}
customElements.define('building-form', BuildingForm);

1 个答案:

答案 0 :(得分:0)

您在super.ready()函数中缺少ready()调用。这是必需的,因为您要扩展PolymerElement

ready() {
    super.ready();
    /* ..and your code.. */
}

此处有更多信息:https://polymer-library.polymer-project.org/3.0/docs/devguide/custom-elements