为AngularDart创建飞镖包

时间:2018-10-26 15:51:19

标签: angular-dart

使用:dart 2.0.0

如何为AngularDart创建组件?

我没有运气,看着https://github.com/dart-lang/angular_components

我已完成以下步骤:

  1. stagehand软件包-简单
  2. export添加到了library <packageName>;的飞镖文件中
  3. 引用了pubspec.yaml

    中的程序包

    您必须依赖build_runner中的pubspec.yaml。 dev_dependencies:   build_runner:> = 0.8.10 <2.0.0 您必须对build_web_compilers中的pubspec.yaml有依赖性。 dev_dependencies:   build_web_compilers:> = 0.3.6 <0.5.0

    请检查以下进口: `import'package:<...> template.dart''

我尝试使用以下方法构建软件包:

 webdev build
webdev could not run for this project.
You must have a dependency on `build_runner` in `pubspec.yaml`.
# pubspec.yaml
dev_dependencies:
  build_runner: >=0.8.10 <2.0.0
You must have a dependency on `build_web_compilers` in `pubspec.yaml`.
# pubspec.yaml
dev_dependencies:
  build_web_compilers: >=0.3.6 <0.5.0

注意:仅使用一个简单的类,它就可以工作-但不适用于Web组件:

这有效:

class Awesome {
  bool get isAwesome => true;
}

这不是:

import 'package:angular/angular.dart';

@Component(
  selector: 'my-card',
  templateUrl: 'my_card.html',
  styleUrls: ['my_card.css'],
  directives: [coreDirectives],
  // pipes: [commonPipes],
)
class MyCard {
  var cardstring = 'My Card - string';
}

无论如何都要使用它:

<my-card></my-card>

1 个答案:

答案 0 :(得分:0)

使用pubspec.yaml(名称,SDK约束,Angular依赖项)创建Dart项目。
lib/my_component.dartlib/my_component.html中创建一个组件文件。 就这样
另外,您也可以将lib/src/my_component.*

这样的文件放入lib/my_components.dart
export 'src/my_component.dart';

在要使用组件包的应用程序项目中,向组件包添加依赖项。

dependencies:
  angular: ^5.0.0
  my_components: ^0.1.0 # requires the package to be published to pub.dartlang.ort
  # alternatively (without publishing
  my_components:
    path: ../my_components
  # or if checked in to GitHub
  my_components:
    git: git://github.com/myaccount/my_components.git

另请参阅https://www.dartlang.org/tools/pub/dependencies

然后您通过导入使用组件

import 'package:my_components/my_components.dart';

@Component(
  selector: ....
  directives: [MyComponent],
  ...
)
class AppComponent {}

并将其添加为AppComponent(或任何其他组件)HTML,

<my-component></my-component>
相关问题