我收到此错误 – “模板解析错误:NgControl没有提供者”
The error comes from this line of code --> <select (ngModel)="currencies" (ngModelChange)="showPurchase($event)" class="annka-center" name="curencies"> <option *ngFor="let money of currencies; let i = index" (ngValue)="money" (click)="showPurchase(money)"> {{money.Currency}} </option> </select>
上面的代码工作顺利,直到我将ReactiveFormsModule添加到我的应用程序.
我在这里尝试了解决方案
ERROR in : No provider for NgControl Angular AOT
但这对我没有用.我正在使用Angular 4.
解决方法
应该
<select [(ngModel)]="currencies" (ngModelChange)="showPurchase($event)" class="annka-center" name="curencies"> <option *ngFor="let money of currencies; let i = index" (ngValue)="money" (click)="showPurchase(money)"> {{money.Currency}} </option> </select>
还要确保在导入下的app.module.ts中导入FormsModule
从’@ angular / forms’导入{FormsModule,ReactiveFormsModule};
@NgModule({ imports: [ FormsModule ]