【问题标题】:Angular2 Template parse errors: Property binding ngFor not used by any directive on an embedded templateAngular2模板解析错误:嵌入模板上的任何指令都没有使用属性绑定ngFor
【发布时间】:2016-05-14 13:52:45
【问题描述】:

这是 Angular2 模板:

<paper-dropdown-menu label="Country">
        <paper-listbox class="dropdown-content" [(ngModel)]="selectedCountry" (ngModelChange)="GetAdmin1s($event)">
            <paper-item *ngFor="let country of countries" value="{{country.Id}}">{{country.Name}}</paper-item>
        </paper-listbox>
    </paper-dropdown-menu>

我收到此错误:

"Template parse errors:
Property binding ngFor not used by any directive on an embedded template (""dropdown-content" [(ngModel)]="selectedCountry" (ngModelChange)="GetAdmin1s($event)">
            [ERROR ->]<paper-item *ngFor="let country of countries" value="{{country.Id}}">{{country.Name}}</paper-item>
 "): LocationComponent@4:12
Property binding ngForCountry not used by any directive on an embedded template (""dropdown-content" [(ngModel)]="selectedCountry" (ngModelChange)="GetAdmin1s($event)">
            [ERROR ->]<paper-item *ngFor="let country of countries" value="{{country.Id}}">{{country.Name}}</paper-item>
 "): LocationComponent@4:12"

Countries 变量定义为:

public countries: Array<Country> = [];

我使用 ngFor 有什么问题?为什么要寻找 ngForCountry?

【问题讨论】:

  • 你确定你在运行 angular2 >= beta-17?
  • 请发一个 plunkr,I'm unable to reproduce this(请随意分叉)
  • 我刚刚升级到 rc.1,但仍然出现错误。我正在尝试使用所涉及的所有依赖项进行 plunkr。

标签: angular polymer


【解决方案1】:

Just try might help

  <paper-dropdown-menu label="Country">
    <paper-listbox class="dropdown-content" [(ngModel)]="selectedCountry" (ngModelChange)="GetAdmin1s($event)">
        <paper-item ngFor #country [ngForOf]="countries" value="{{country.Id}}">{{country.Name}}</paper-item>
    </paper-listbox>
  </paper-dropdown-menu>

【讨论】:

  • 我认为这行得通。相反,我在代码的另一部分出现错误。 “[LocationComponent@3:48 中的选定国家/地区] 中没有 '' 的值访问器”
  • @JonasArcangel 对于value accessor 错误消息请参阅stackoverflow.com/questions/37202543/…
  • @mayur 这很奇怪。这个ngFor 语法应该只适用于&lt;template&gt;。非常有趣的发现!
【解决方案2】:

你可以试试: *ngFor="#country of countries"

【讨论】:

  • 我认为不再使用这种语法了。我收到“没有 e 提供者!(e -> e)”错误。
猜你喜欢
  • 2018-11-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-04-23
  • 1970-01-01
  • 2017-05-12
  • 2016-12-25
  • 2017-12-19
相关资源
最近更新 更多