在dart angular2中使用组件中的纸张标签

时间:2016-04-19 13:58:36

标签: angular dart dart-polymer

我试图在dart angular2组件中使用聚合物纸标签,但我无法使用。我在下面的代码中缺少什么?

在以下代码中,index.html模板中指定的paper-tabs工作正常,但main-app.html中的paper-tabs格式不正确,在没有任何正确动画的情况下单击时消失。

pubspec.yaml

name: tabs_test
version: 0.0.1
description: Test Paper Tabs
environment:
  sdk: '>=1.13.0 <2.0.0'
dependencies:
  angular2: ^2.0.0-beta.13.1
  polymer: ^1.0.0-rc.16
  polymer_elements: ^1.0.0-rc.8
transformers:
- polymer:
    entry_points: web/index.html
- angular2:
    platform_directives:
    - 'package:angular2/common.dart#COMMON_DIRECTIVES'
    - 'package:angular2/common.dart#FORM_DIRECTIVES'
    platform_pipes:
    - 'package:angular2/common.dart#COMMON_PIPES'
    entry_points: web/main.dart

的index.html

<!DOCTYPE html>
<html>
  <head>
    <title>Tab Test</title>
    <script defer src="main.dart" type="application/dart"></script>
  </head>
  <body>
    <main-app></main-app>
    <paper-tabs selected="0"> <!-- THESE WORK -->
      <paper-tab>INDEX ITEM ONE</paper-tab>
      <paper-tab>INDEX ITEM TWO</paper-tab>
      <paper-tab>INDEX ITEM THREE</paper-tab>
    </paper-tabs>
  </body>
</html>

main.dart

import 'package:polymer/polymer.dart';
import 'package:angular2/platform/browser.dart';
import 'package:tabs_test/views/main_app/main_app.dart';

main() async {
  await initPolymer();
  bootstrap(MainApp, []);
}

main_app.dart

import 'package:angular2/angular2.dart';
import 'package:polymer_elements/paper_tabs.dart';
import 'package:polymer_elements/paper_tab.dart';

@Component(selector: 'main-app',
    templateUrl: 'main_app.html',
    providers: const[],
    directives: const []
)
class MainApp {
  MainApp() { }
}

main_app.html

<paper-tabs selected="0"> <!-- THESE DO NOT WORK -->
  <paper-tab>MA ITEM ONE</paper-tab>
  <paper-tab>MA ITEM TWO</paper-tab>
  <paper-tab>MA ITEM THREE</paper-tab>
</paper-tabs>

1 个答案:

答案 0 :(得分:3)

通常,当Polymer与Angular2一起使用时,您需要启用完整的阴影DOM

在其他脚本标记之前添加此内容

<script src="packages/web_components/webcomponents.js"></script>
<script>
   /* this script must run before Polymer is imported */
   window.Polymer = {
     dom: 'shadow',
     lazyRegister: true
   };
 </script>

有关此主题的更多详细信息,请参阅https://dart.academy/dart-angular-2-and-polymer-together/

Repo project on GitHub