这是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"
国家变量定义为:
public countries: Array<Country> = [];
我使用ngFor有什么问题?为什么要寻找ngForCountry?
解决方法
@H_404_30@ 试试可能有帮助<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>