dart - Paper-Dialog 可以与 AngularDart 一起使用吗

标签 dart polymer angular-dart paper-dialog

Polymer 的纸质对话框可以与 Angular2 Dart 一起使用吗?我能找到的唯一讨论是一个问题 here .

我尝试将代码合并到我的角度组件中。它不喜欢 $['dialogArtist']在打开的对话框中。然后我创建一个新类

class ArtistDialog extends PolymerElement {...
$['dialogArtist]在那里工作。然后我遇到了表单数据的问题。它一直在组件中而不是对话框中寻找它。对话框 html 与组件 html 位于同一文件中,因此可能与它有关。当我注释掉表格时。它提示对话框类缺少初始化程序。有没有从 Angular2 Dart 组件打开 Polymer 纸质对话框的示例?

我想我需要知道的就是我需要在组件中放入什么来打开一个对话框并从中获取数据。我认为上面链接中的示例对于对话框类来说是一个很好的示例。还有对话框html去哪里了?

我的角度分量的相关部分:
@Component(selector: 'my-artists',
templateUrl: 'artists_component.html',
//encapsulation: ViewEncapsulation.Native,  // added for polymer
styleUrls: const['artist.css']
)

class ArtistsComponent implements OnInit {
  ...
  ArtistDialog editDialog;

  void ngOnInit() {
    getArtists();
    editDialog = new ArtistDialog.created();
  }

  void onEditArtist() {
    editArtist = selectedArtist;
    editDialog.open;
  }

我的 polymer 成分:
//@CustomTag('dialogArtist'); //uncomment this cause and error
class ArtistDialog extends PolymerElement {

  String birth_year;

  ArtistDialog.created() : super.created();
  //@observable int selected = 0; // uncommenting this causes and error

  void open() {
    $['dialogArtist'] as PaperDialog..open();
  }
}

索引.html:
<!DOCTYPE html>
<html>
<head>
<title>Jazz Cat</title>
<script>
  window.Polymer = window.Polymer || {};
  window.Polymer.dom = 'shadow';
</script>

<!-- For testing using pub serve directly use: -->
<base href="/">
<!-- For testing in WebStorm use: -->
<!-- <base href="/dart/web/"> -->

<link rel="import" href="packages/polymer/polymer.html">
<link rel="import" href="packages/polymer_elements/iron_flex_layout.html">
<link rel="import" href="packages/polymer_elements/paper_header_panel.html">
<link rel="import" href="packages/polymer_elements/paper_toolbar.html">
<link rel="import" href="packages/polymer_elements/paper_menu.html">
<link rel="import" href="packages/polymer_elements/paper_item.html">
<link rel="import" href="packages/polymer_elements/paper_menu_button.html">
<link rel="import" href="packages/polymer_elements/paper_input.html">
<link rel="import" href="packages/polymer_elements/paper_dialog.html">
<link rel="import" href="packages/polymer_elements/iron_list.html">
<link href="master.css" rel="stylesheet" type="text/css" />

<style is="custom-style">

这是我的对话框的 html。它与组件 html 在同一个文件中。
<polymer-element name="dialogArtist">
  <paper-dialog id="dialog">
    <p>This is a dialog.</p>
  </paper-dialog>
</polymer-element>

最佳答案

结果比我想象的要容易。它像许多其他纸张元素一样工作。在我的角度组件 Dart 文件中,我有:

import 'package:polymer_elements/paper_input.dart';
import 'package:polymer_elements/paper_button.dart';
import 'package:polymer_elements/paper_dialog.dart';
...
class ArtistsComponent implements OnInit {
...
 PaperDialog artistDialog;
 // Dialog fields
 String birth_year;
....
 void ngOnInit() {
    getArtists();
    artistDialog = querySelector('#artistDialog');
...
  void onEditArtist() {
    birth_year = selectedArtist.birth_year;
    artistDialog.open();
  }

  void onDialogSubmit([bool enter = false]) {
    selectedArtist.birth_year = birth_year;
  }
  void onDialogCancel() {
    print("canceled");
  }

在我的组件 templateUrl 文件中,我有:
...
<paper-item (click)="onEditArtist()">Edit</paper-item>

这就是我调用对话框的方式,让您了解一种方法。在 html 其余部分之外的同一文件中:
<paper-dialog id="artistDialog">
  <form #artistForm="ngForm">
    <h3>Edit Artist</h3>
    <paper-input #artistInput type="text" ngDefaultControl
                                [(ngModel)]="birth_year" ngControl="artistInputCtrl"
                                label="Birth Year" required allowed-pattern="[0-9]" maxlength="4"
                                (keyup.enter)="onDialogSubmit(true)">
      {{ birth_year }}
    </paper-input>
    <div>
      <paper-button (click)="onDialogCancel()" raised dialog-dismiss>Cancel</paper-button>
      <paper-button (click)="onDialogSubmit()" raised dialog-confirm autofocus>Accept</paper-button>
    </div>
  </form>
</paper-dialog>

这是我在 Polymer 中的第一个表单,也是我的第一个对话框,所以这可能不是最干净的方式。另外,我只在 Dartium 和 Chrome 中进行了测试。表格代码来自 this article

关于dart - Paper-Dialog 可以与 AngularDart 一起使用吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39090750/

相关文章:

google-chrome-extension - 为什么dart.io之类的只能在命令行应用中使用?

dart - 在同一应用程序中运行 Normal Dart HTML 和 Angular Dart 2

dart - 尽管使用Dart 2.0,仍无法省略 'new'关键字

dart json.encode(data) 不能接受其他语言

dart - 底部居中容器中的一些小部件

dart - 在Dart中使用JSON参数调用Chromecast Receiver Library的JavaScript函数

polymer - 更改进纸宽度

javascript - 如何在网页编程中显示适合屏幕的图像列表

flutter - 我无法使用 google_sign_in 在 Flutter 中登录我的 Google 帐户

javascript - JayData : how to migrate code from v1. 3 到 v1.5