我收到此错误 - "模板解析错误: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>
Run Code Online (Sandbox Code Playgroud)
上面的代码工作顺利,直到我将ReactiveFormsModule添加到我的应用程序.
我在这里尝试了解决方案
错误:没有NgControl Angular AOT的提供者
但这对我没有用.我正在使用Angular 4.
我正在尝试在我的应用中第一次使用ngControl:
<md-input placeholder="Amount" value="0" ngControl="ammount" required></md-input>
Run Code Online (Sandbox Code Playgroud)
在我的组件中添加了以下内容:
import { FORM_PROVIDERS,FORM_DIRECTIVES } from '@angular/common';
..
directives: [MD_INPUT_DIRECTIVES,
FORM_DIRECTIVES,
],
providers: [FORM_PROVIDERS],
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
browser_adapter.ts:78 EXCEPTION: Error: Uncaught (in promise): Template parse errors:
No provider for ControlContainer ("
[ERROR ->]<md-input placeholder="Amount" value="0" ngControl="ammount" required></md-input>
Run Code Online (Sandbox Code Playgroud)
我错过了什么?
ng test 显示以下错误,但它在现实中按预期工作。
Error: Template parse errors:
No provider for NgControl ("
<div class="form-group">
<label class="control-label">Location</label>
[ERROR ->]<select class="selectpicker" *ngIf="locations" data-style="btn btn-primary btn-round" title="Select A"): VehicleFormComponent@27:4
No provider for NgControl (" <div class="form-group label-floating">
<label class="control-label">Is Available</label>
[ERROR ->]<md-slide-toggle [(ngModel)]="isAvailable" color="primary" [ngModelOptions]="{standalone: true}">
"): VehicleFormComponent@41:4 in src/test.ts (line 25739)
Expected undefined to be truthy.
Run Code Online (Sandbox Code Playgroud)
我认为这主要是因为添加[ngModelOptions]="{standalone: true}"了自定义标签。