Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/visual-studio-code/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Dart 将选定的材质绑定到我的模型_Dart_Material Design_Angular Dart_Angular Components - Fatal编程技术网

Dart 将选定的材质绑定到我的模型

Dart 将选定的材质绑定到我的模型,dart,material-design,angular-dart,angular-components,Dart,Material Design,Angular Dart,Angular Components,我有一个简单的用例——我在AngularDart应用程序中使用了一个丰富的对象模型,我想要一个组件向我显示模型的一个字段的当前状态,并且我想要在选择更改时调用模型上的一个方法(这将最终更新绑定到该字段的字段) 大概是这样的: app-component.dart: @Component( selector: 'my-app', styleUrls: const ['app_component.css'], templateUrl: 'app_component.html', di

我有一个简单的用例——我在AngularDart应用程序中使用了一个丰富的对象模型,我想要一个组件向我显示模型的一个字段的当前状态,并且我想要在选择更改时调用模型上的一个方法(这将最终更新绑定到该字段的字段)

大概是这样的:

app-component.dart:

@Component(
  selector: 'my-app',
  styleUrls: const ['app_component.css'],
  templateUrl: 'app_component.html',
  directives: const [CORE_DIRECTIVES, materialDirectives],
  providers: const [materialProviders],
)
class AppComponent {
  Model myModel = new MyModel();
  SelectionModel<String> selectModel = new SelectionModel();
}
@组件(
选择器:“我的应用程序”,
styleURL:const['app_component.css'],
templateUrl:'app_component.html',
指令:const[CORE_指令,materialdirections],
提供者:常量[材料提供者],
)
类AppComponent{
Model myModel=新的myModel();
SelectionModel selectModel=新建SelectionModel();
}
app-component.html:

<material-dropdown-select
   [options]='myModel.listOfOptions'
   [buttonText]='myModel.currentOption'
   [selection]='selectModel'>
   <!-- call myModel.changeOption(selectedOption) when selection changes -->
</material-dropdown-select>

将setter附加到您的
selectModel
成员,并在其中运行代码,同时更新“real”值(private member)。当然,您需要匹配的getter。

selectModel.selectionChanges.listen(update);
selectModel.selectionChanges.listen(update);

void update(List<SelectionChangeRecord> record) {
  ...
}
作废更新(列表记录){ ... }
我希望这能帮助你,如果你有兴趣的话,看看。

我还是有点困惑。。。谁打电话给二传手?我知道我可能很笨,但像这样的?SelectionModel _selectModel=新建SelectionModel();SelectionModel获取selectModel{return _selectModel;}设置selectModel(SelectionModel){_selectModel=model;_selectModel.selectionChanges.listen(updateSelection);}如果是,则它不起作用。更改选择时未调用setter。您可能希望代码在生命周期中的错误点更新值。也许这会让事情变得更清楚。您可能在更改有机会发布之前就在寻找更改。我在setter中放入了一个“print”语句,它不会将任何内容打印到控制台。你能提供一个最小的工作示例吗?嗨,你能在github中分享你的代码吗?我有一个错误:
异常:断言失败:org dartlang-app:///packages/angular_components/material_select/material_dropdown_select_accessor.dart:118:12 _select.selection==null“使用下拉控件值访问器时无法设置[选择]。