我有一个带有物料下拉选择的组件,并且当[[selection]]的类型为SingleSelectionModel时,出现错误“ angular dart预期值为'SingleSelectionModel'的值,但类型为'Term'的值”。当它是Term类型时就可以了。 我需要SingleSelectionModel来访问其更改流并使用所选值进行一些操作。
我有Dart 2.2.0,角度:^ 5.2.0,angular_components:^ 0.11.0。
有人可以帮助将SingleSelectionModel用于[(选择)]吗?
@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';
}
答案 0 :(得分:0)
最后,我发现了一个解决方案,大多数是偶然的。使用
时 SingleSelectionModel<Term> selectedTerm = SelectionModel<Term>.single();
模板绑定必须仅是[]而不是[()],因此正确的模板是
template: '''
<material-dropdown-select
[options]="terms"
[selection]="selectedTerm"
[buttonText]="buttonText">
</material-dropdown-select>
''',