繁体   English   中英

如何使用angular2_components

[英]How to use angular2_components

有人可以告诉我如何使用angular2_components吗? 我尝试如下:

<material-button>Test</material-button> 

但是它没有显示预期的按钮。

更新我的工作:

pubspec yaml:

dependencies:
  angular2: ^2.0.0
  angular2_components: ^0.1.0
dev_dependencies:
  browser: ^0.10.0
  dart_to_js_script_rewriter: ^1.0.1
transformers:
- angular2:
    platform_directives:
    - 'package:angular2/common.dart#COMMON_DIRECTIVES'
    platform_pipes:
    - 'package:angular2/common.dart#COMMON_PIPES'
    entry_points: web/main.dart

app_component.dart:

import 'package:angular2/core.dart';
import 'package:angular2_components/angular2_components.dart';

@Component(
    selector: 'my-app',
    directives: const[
      MaterialButtonComponent,
    ],
    styleUrls: const ['app_component.css'],
    templateUrl: 'app_component.html')
class AppComponent {}

该按钮仍然看起来像: 在此处输入图片说明

并收到错误消息: 在此处输入图片说明

我究竟做错了什么?

您需要添加

dependencies:
  angular2_components: ^0.1.1

pubspec.yaml文件并运行pub get

然后,您需要导入MaterialButtonComponent

import 'package:angular2_components/angular2_components.dart'
    show MaterialButtonComponent, materialProviders; // the show Xxx is optional

然后将其添加到要使用它的组件的@Directives()

@Component(
  selector: 'my-app',
  directives: const [
    MaterialButtonComponent,
  ],
  providers: [materialProviders],
  ...
)

有关更多详细信息,请参见https://dart-lang.github.io/angular2_components_example/https://github.com/dart-lang/angular2_components_example/blob/master/lib/app_component.html

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM