dart - 自定义Angular Dart组件包

标签 dart angular-dart dart-pub dart-html

我创建了一个试图在我的主项目中使用的 Angular Dart 组件。我正在使用路径包来引用它。组件的构造函数(在dart文件中)被调用,但是出现错误,找不到.css和.html文件。它在寻找它们的路径似乎存在,因此我不确定为什么找不到它们。

我在整个代码中都使用了其他自定义组件,但是没有与之关联的html或css文件,它们也很好,似乎仅限于html和css文件。

这是我的代码片段

位于test_component / lib / test_component /中的test.dart

library TestCom;

import 'package:angular/angular.dart';

@Component(
    selector: 'tester',
    templateUrl: 'test.html',
    cssUrl: 'test.css')
class TestComponent {
 String t = "this is the test component";

 TestComponent() {
    print("Test Component STARTED");
  }
}

位于test_component / lib / test_component /中的test.html
<h3>{{t}}</h3>

pubspec.yaml位于test_component中
name: TestModule
dependencies:
  angular: "^1.1.2+2"
  browser: any
transformers:
- angular:
    html_files:
      - lib/test_component/test.html

main.dart位于main / src / main / dart / web中
import 'package:TestModule/test_component/test.dart';

class MyAppModule extends Module {
  MyAppModule() {
    bind(TestComponent);
  }
}

位于main / src / main / dart / web /中的index.html
<tester></tester>

pubspec.yaml位于main / src / main / dart中
name: main_package
dependencies:
  angular: "^1.1.2+2"
  browser: any
  shadow_dom: any
  json_object: any   
  bootjack: any
  crypto: any
  xml: "^2.3.2"
  TestModule:
    path: ../../../../test_component
transformers:
- angular:

运行pub get之后,在我的主项目的packages文件夹中,存在TestModule / test_component /,其中包含test.css,test.dart和test.html。我不确定为什么我在运行它时找不到.html和.css文件。

这是我运行控制台时显示的内容
Observatory listening at http://127.0.0.1:54254/
Test Component STARTED
index.html:1 GET http://127.0.0.1:3030/packages/TestModule/test_component/test.css 404 (Not Found)
index.html:1 GET http://127.0.0.1:3030/packages/TestModule/test_component/test.html 404 (Not Found)
2 HTTP 404: <html><head><title>404 Not Found</title></head><body>File not found</body></html>

STACKTRACE:
null

最佳答案

试试这个

 name: TestModule
    dependencies:
      angular: "^1.1.2+2"
      browser: any
    transformers:
    - angular:
        html_files:
          - packages/TestModule/test_component/test.html

但是对于css文件,我认为您只需要将它们与组件的Dart文件放入同一文件夹即可。

关于dart - 自定义Angular Dart组件包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33552909/

相关文章:

android-studio - 尚未在Android Studio中运行“发布获取”

dart - 调试 Angular 和 Polymer dart

flutter - 如何在我的 pubspec.yaml 配置中指定本地 git 存储库的分支?

flutter - 使用flever常量最佳实践,而不是使用dependentOnInheritedWidgetOfExactType。

json - Flutter/Dart 错误 - NoSuchMethodError : Class '_InternalLinkedHashMap<String, dynamic>' has no instance method 'map' with matching arguments

dart - 如何在组件范围之外引用 AngularDart 组件属性

dart - 自动生成protobuf注释的类

Flutter 默认图像占位符

dart - 在 Flutter 中显示本地镜像和服务器图像(带缓存)

flutter - 如何在 Flutter 回调中使用可变参数?