Polymer 的 paper-dialog not working 打不开

Polymer's paper-dialog not working can't be opened

我正在尝试实现一个纸质对话框,当点击下图中的纸质工厂时,它会自动显示: my app's main screen

但是我无法打开纸质对话框。

我已经在我的应用程序中实现了纸质对话,如下所示:

<link rel="import" href="../bower_components/polymer/polymer.html">
<link rel="import" href="../bower_components/polymerfire/firebase-query.html">
<link rel="import" href="../bower_components/paper-fab/paper-fab.html">
<link rel="import" href="../bower_components/paper-dialog/paper-dialog.html">
<link rel="import" href="../bower_components/polymerfire/firebase-auth.html">
<link rel="import" href="shared-styles.html">

<dom-module id="my-view1">
  <template>
    <style include="shared-styles">
      :host {
        display: block;

        padding: 10px;
      }

      paper-fab{
        position:fixed;
        right:20px;
        bottom:68px;
        --paper-fab-keyboard-focus-background:--accent-color;
      }
    </style>
    <firebase-auth 
      id="auth" 
      user="{{user}}" 
      provider="" 
      status-known="{{statusKnown}}"
      on-error="handleError">
    </firebase-auth>
     <firebase-query
        id="query"
        path="/posts"
        data="{{posts}}">
    </firebase-query>
    <div class="card">
      <h1>Post</h1>

      <ul id="post-list">
        <template is="dom-repeat" items="[[posts]]" as="post">
          <li>
            <p class="content">[[post.body]]</p>
          </li>
        </template>
      </ul>

    </div>
    <paper-fab icon="add" onclick="dialog.open()"></paper-fab>

    <paper-dialog id="dialog">
      <paper-textarea id="post" label="Write your post here..."></paper-textarea>
      <paper-button dialog-dismiss>Cancel</paper-button>
      <paper-button on-tap="post" id="btnPost" raised class="indigo" hidden$="[[!user]]">Post</paper-button>
    </paper-dialog>
  </template>

  <script>
    Polymer({
      is: 'my-view1',
      properties:{
        user:{
          type: Object
        },
        statusKnown:{
           type: Object
        },
        posts: {
          type: Object
        }
      },
      post: function() {
        this.$.query.ref.push({
          "Uid": this.user.uid,
          "body": this.$.post.value
        });
        this.$.post.value = null;
      }
    });
  </script>
</dom-module>

    <paper-fab icon="add" onclick="dialog.open()"></paper-fab>

    <paper-dialog id="dialog">
      <paper-textarea id="post" label="Write your post here..."></paper-textarea>
      <paper-button dialog-dismiss>Cancel</paper-button>
      <paper-button on-tap="post" id="btnPost" raised class="indigo" hidden$="[[!user]]">Post</paper-button>
    </paper-dialog>

这里的这段代码摘自本页的演示:

https://www.webcomponents.org/element/PolymerElements/paper-dialog/v1.1.0/demo/demo/index.html

但是当我实际点击 paper-fab 时,出现以下错误:

Uncaught ReferenceError: dialog is not defined at HTMLElement.onclick (view3:1) onclick @ view3:1

有谁知道如何在轻按造纸厂时打开造纸对话框?我想我遗漏了一些包含,但我不知道是哪一个。

首先不要使用onclick。有一些 Polymer 事件属性,例如单击或点击。其次,您应该调用将打开所选对话框的函数

示例:

<paper-fab icon="add" on-tap="_openDialog"></paper-fab>

和内部脚本

_openDialog: function() {
  this.$.dialog.open();
}

this.$.dialog 查找带有 id 对话框的元素并调用函数 open