如何在聚合物应用程序中实现主要功能 [英] how to implement a main function in polymer apps

查看:156
本文介绍了如何在聚合物应用程序中实现主要功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在使用聚合物的应用程序中实现主要功能。



我试图在dart文件中实现main函数,其中实现了聚合物代码。
不执行代码。



不允许包含带有main函数的第二个dart脚本 -



我的错误在哪里?
Tnx Mica。

解决方案

index.html

 < head> 
<! - < link rel =importhref =packages / polymer / polymer.html>不再需要(仅在元素中) - >
<! - < script src =packages / web_components / platform.js>< / script>
不再需要Polymer> = 0.14.0 - >
<! - < script src =packages / web_components / dart_support.js>< / script>
不再需要Polymer> = 0.15.0 - >

<! - old - >
< script type =application / dart>
export'package:polymer / init.dart';< / script>

<! - new - >
< script type =application / dart> export'index.dart';< / script>
< / head>
< body>
...
<! - ...当您使用自定义main方法时(请参阅https://code.google.com/p/dart/issues/detail?id=17546# c16)→
< script type =application / dartsrc =index.dart>< / script>
< / body>

index.dart



Polymer 0.17.0 (Polymer.js 1.0)

  main()async {
await initPolymer();
//这里的任何其他代码。
}

Before Polymer 0.17.0

Polymer 0.16.1 介绍了一种更简单的初始化方法。
而不是 main()使用注释为的方法@whenPolymerReady

  //> = Polymer 0.16.1 
import'package:polymer /聚合物
export'package:polymer / init.dart';

@whenPolymerReady
void onReady(){
///这里是自定义安装代码。
}

Before Polymer.dart 0.16.1 p>



  //> = Polymer 0.16.0 
importpackage:polymer / polymer.dart;

main(){
initPolymer()。then((zone)=> zone.run((){
//这里的代码大部分时间$ b Polymer.onReady.then((_){
//一些事情必须等待直到onReady回调被调用
//示例看下面链接的讨论
});
}));
}

有关更多详细信息,请参阅Polymer 0.16.0的更改日志b https://pub.dartlang.org/packages/polymer



Before Polymer 0.16.0

  //<聚合物0.16.0 
importpackage:polymer / polymer.dart;

main(){
initPolymer()。run((){
//这里的代码大部分时间都在工作
Polymer.onReady.then ){
//一些东西必须等到onReady回调被调用
//为例子看下面的讨论
}};
});
}

在dartium中工作的简单工具提示,而不是javascript


I want to implement a main function in an app using polymer.

I tried to implement the main function in the dart file, where the polymer code is implemented. The code is not executed.

Including a second dart script with the main function is not allowed-

Where is my mistake? Tnx Mica.

解决方案

index.html

 <head>
   <!-- <link rel="import" href="packages/polymer/polymer.html"> not necessary anymore (only in elements)-->
   <!-- <script src="packages/web_components/platform.js"></script>
        not necessary anymore with Polymer >= 0.14.0 -->
   <!-- <script src="packages/web_components/dart_support.js"></script> 
        not necessary anymore with Polymer >= 0.15.0 -->

   <!-- old -->
   <script type="application/dart">
      export 'package:polymer/init.dart';</script> 

   <!-- new  -->
   <script type="application/dart">export 'index.dart';</script>
 </head>
 <body>
   ...
   <!-- ... when you use a custom main method (see https://code.google.com/p/dart/issues/detail?id=17546#c16) -->
   <script type="application/dart" src="index.dart"></script>
 </body>

index.dart

Polymer 0.17.0 (Polymer.js 1.0)

main() async {
  await initPolymer();
  // Any other code here.
}

Before Polymer 0.17.0

Polymer 0.16.1 introduces a simpler way of initialization. Instead of main() use a method annotated with @whenPolymerReady

// >= Polymer 0.16.1
import 'package:polymer/polymer.dart';
export 'package:polymer/init.dart';

@whenPolymerReady
void onReady() {
  /// Custom setup code here.
}

Before Polymer.dart 0.16.1

// >= Polymer 0.16.0
import "package:polymer/polymer.dart";

main() {
  initPolymer().then((zone) => zone.run(() {
    // code here works most of the time
    Polymer.onReady.then((_) {     
      // some things must wait until onReady callback is called
      // for an example look at the discussion linked below
    });
  }));
}

For more details look at the changelog of Polymer 0.16.0 at https://pub.dartlang.org/packages/polymer

Before Polymer 0.16.0

// < Polymer 0.16.0    
import "package:polymer/polymer.dart";

main() {
  initPolymer().run(() {
    // code here works most of the time
    Polymer.onReady.then((_) {     
      // some things must wait until onReady callback is called
      // for an example look at the discussion linked below
    });
  });
}

simple tooltip working in dartium, not as javascript

这篇关于如何在聚合物应用程序中实现主要功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆