【发布时间】:2019-03-16 16:49:51
【问题描述】:
我有一个带有材质下拉选择的组件,当 [(selection)] 的类型为 SingleSelectionModel 时,我收到错误消息“角镖预期的值类型为‘SingleSelectionModel’,但得到的类型为‘Term’”。当它是 Term 类型时,它很好。 我需要 SingleSelectionModel 来访问其更改流并对选定的值进行一些操作。
我有 Dart 2.2.0,角度:^5.2.0,角度组件:^0.11.0。
谁能帮助如何将 SingleSelectionModel 用于 [(selection)]?
@Component(
selector: 'x-plan-edit-rule',
template: '''
<material-dropdown-select
[options]="terms"
[(selection)]="selectedTerm"
[buttonText]="buttonText">
</material-dropdown-select>
''',
directives: const [
coreDirectives,
MaterialButtonComponent,
MaterialDropdownSelectComponent,
],
)
class EditPlanRuleComponent implements OnInit {
@Input() Rule rule;
SelectionOptions<Term> terms;
SingleSelectionModel<Term> selectedTerm = SelectionModel<Term>.single(); // GIVES ERROR
//Term selectedTerm; // WORKS FINE WITHOUT ERROR
EditPlanRuleComponent();
@override
ngOnInit() {
// List<Term> rule.availableTerms
terms = SelectionOptions.fromList(rule.availableTerms);
selectedTerm?.selectionChanges?.listen((_) {
// do some checks after the selection change
});
}
String get buttonText => 'Some button text';
}
【问题讨论】:
标签: dart angular-dart