在AngularDart中,我应该如何引用templateUrl中的模板,以便它们同时适用于Dartium和dart2js?

在AngularDart中,我应该如何引用templateUrl中的模板,以便它们同时适用于Dartium和dart2js?,dart,angular-dart,dart-pub,Dart,Angular Dart,Dart Pub,我目前有以下目录布局: project web app.html main.dart templates app.html alerts.html menu.html components AppComponent.dart AlertsComponent.dart MenuComp

我目前有以下目录布局:

project
    web
        app.html
        main.dart
        templates
            app.html
            alerts.html
            menu.html
        components
            AppComponent.dart
            AlertsComponent.dart
            MenuComponent.dart
        resources
            css
                bootstrap.css
我的组件看起来像:

@组件(
选择器:“应用程序”,
templateUrl:'templates/app.html'
)
类AppComponent{…}
我的应用程序的index.html(在另一个项目中)由
/client
提供,
project/web
/project
提供。上述方法在Dartium中有效,但我从发布构建中得到错误:

[Warning from _Serial on project|web/main.dart with input project|web/components/AppComponent.dart]:
line 3, column 1 of web/components/AppComponent.dart: Unable to find templates/app.html at project|templates/app.html
@Component(
^^^^^^^^^^^

取决于我在
templateUrl
html\u文件中使用的路径组合(用于Angular的transformer)

templateUrl
pubspec.yaml
中,究竟应该引用什么,应该在哪里引用,以及如何引用

更新:我可以通过将模板移动到
lib
目录并使用
templateUrl:'packages/project/templates/app.html'
,来消除构建错误,但Dartium尝试将其加载为
/packages/project/templates/app.html
,而不是
/project/packages/project/templates/app.html
,这是正确的。我看不出任何方法来告诉它基本URL是什么

但Dartium试图将其加载为 /包/project/templates/app.html,而不是 /project/packages/project/templates/app.html,这是正确的。 我看不出任何方法来告诉它基本URL是什么

我相信您正在使用angulardart 1.1.1或1.1.2?在从1.1.0切换到1.1.2之后,我们的项目中出现了相同的问题。这是自1.1.1版以来添加的奇怪行为

出于某种原因,AngularDart中的默认包根现在是“/packages/”。这会导致生成根相对URL。在你的情况下,它会产生

/packages/project/templates/app.html
而不是

packages/project/templates/app.html
当您的应用程序位于域的根目录下时,一切正常。但在您的情况下,需要做的是将以下内容添加到main.dart中的初始化方法中:

bind(ResourceResolverConfig, toValue: new ResourceResolverConfig
         .resolveRelativeUrls(true, packageRoot: 'packages/'));
这将覆盖angular的默认包根,并使其生成正确的相对URL


希望能有所帮助。

我收到的警告与第一个警告完全相同,关于找不到模板。问题是,它在dart和dart2js中对我有效。可能是输出错误?我们可能应该向Angular.dart报告。虽然遵循教程中的项目结构,但您的组件和模板不应该位于
lib
文件夹中吗?我也有同样的问题。我注意到angular.dart中有一个测试,它使用组件templateUrl的绝对路径!我认为最好的办法是忽略错误,但我听说是这样。有人知道[Warning from _Serial]:无法从pubspec.yaml的html文件中找到webatara | web/main.dart的修复方法吗。?
packages/project/templates/app.html
bind(ResourceResolverConfig, toValue: new ResourceResolverConfig
         .resolveRelativeUrls(true, packageRoot: 'packages/'));