聚合物的纸质对话框无法打开



我正在尝试实现一个纸质对话框,当点击下图中的纸厂时,该对话框将显示出来:我的应用主屏幕

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

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

<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

但是当我实际点击纸厂时,出现以下错误:

捕获的引用错误:未定义对话框 at HTMLElement.onclick (view3:1( 点击 @ 视图3:1

有谁知道我如何在点击纸质工厂时打开纸质对话框?我想我缺少一些包含,但我无法弄清楚是哪一个。

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

例:

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

和内部脚本

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

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

最新更新