找不到带有简单组件的RadioControlRegistry提供程序

时间:2019-07-05 19:04:02

标签: angular-dart

我有一个简单的Angular-Dart组件,尝试在单选输入中将connect属性连接到ngModel,应用正确编译,但是浏览器控制台给我错误:

No provider found for RadioControlRegistry: RadioControlValueAccessor                        
-> RadioControlRegistry.

有代码:

import 'package:angular/angular.dart';
import 'package:angular_forms/angular_forms.dart';

@Component(
  selector: 'order-question-test',
  template: '''
    <input type="radio" name="food" [(ngModel)]="foodChicken">
    <input type="radio" name="food" [(ngModel)]="foodFish">
       ''',
  directives: [
    coreDirectives,
    formDirectives,
  ]
)

class OrderQuestion {
  RadioButtonState foodChicken = RadioButtonState(true, "chicken");
   RadioButtonState foodFish = RadioButtonState(false, "fish");
  OrderQuestion ();
}

pubspec.yaml

environment:
  sdk: '>=2.2.0 <3.0.0'

dependencies:
  angular: ^5.2.0
  angular_components: ^0.13.0
  json_annotation: ^2.0.0

dev_dependencies:
  angular_test: ^2.2.0
  build_runner: ^1.5.0
  build_test: ^0.10.3
  build_web_compilers: ^1.0.0
  json_serializable: ^2.0.0
  pedantic: ^1.0.0
  test: ^1.5.1

怎么了?

2 个答案:

答案 0 :(得分:0)

尝试在providers数组下添加 RadioControlRegistry

 providers: [ClassProvider(RadioControlRegistry)]

答案 1 :(得分:0)

您的组件中需要providers: [FORM_PROVIDERS]

@Component(
  selector: 'order-question-test',
  template: '''
    <input type="radio" name="food" [(ngModel)]="foodChicken">
    <input type="radio" name="food" [(ngModel)]="foodFish">
       ''',
  directives: [
    coreDirectives,
    formDirectives,
  ],
  providers: [FORM_PROVIDERS]  // added
)

class OrderQuestion {
  // ...
}