将ReactiveFormsModule添加到我的angular 4应用程序后,没有获得NgControl错误的提供程序

前端之家收集整理的这篇文章主要介绍了将ReactiveFormsModule添加到我的angular 4应用程序后,没有获得NgControl错误的提供程序前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我收到此错误 – “模板解析错误: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      
    ]

猜你在找的Angularjs相关文章