Dart实现的Angular 2指令ngFor生成错误

4
在使用Angular 2 Beta 0的Dart实现中尝试使用ngFor指令时,会生成以下编译时错误。
Property binding ngForOf not used by any directive on an embedded  template ("[ERROR ->]
<div *ngFor="#item of items">
{{item}}
</div>"):

组件:

library design;

import 'package:angular2/angular2.dart';

@Component(
    selector: 'design-component',
    templateUrl: 'design.html',
    viewProviders: const [CORE_DIRECTIVES]
)
class DesignComponent {
   List<String> items = ["One", "Two", "Three"];
}

模板:

<div *ngFor="#item of items">
   {{item}}
</div>

如果有任何建议或帮助需要,我们将不胜感激。

2个回答

4

viewProviders 应该改为 directivesviewProviders 用于依赖注入。


当我尝试在Angular 2 Beta中使用ng2_form_examples时,仍然会收到相同的错误。属性绑定ng-forOf在嵌入式模板上未被任何指令使用 (https://goo.gl/RWSnR7) - Suresh
实际上,这对我有效。我只是错过了我的示例应用程序模板中另一个 ng-for。当我将其更改为 ngFor 时,一切都正常工作了。 - Günter Zöchbauer

0
我的解决方法是更改以下内容:
<li *ng-for="#name of friendNames">

致:

<li *ngFor="#name of friendNames">

在我的模板中。

这是我的组件:

@Component(selector: "app",
           directives: const [NgFor],
           templateUrl: 'app_component.html')
class AppComponent{
    List<String> friendNames = const ["a", "b", "c"];
}

Gunther Zochbauer在评论中提到了这一点。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接