2017-06-12 25 views
0

我有一个简单的使用案例 - 我有一个丰富的对象模型,我在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(); 
} 

APP-component.html:

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

回答

1
selectModel.selectionChanges.listen(update); 

void update(List<SelectionChangeRecord> record) { 
    ... 
} 
0

连接二传手您selectModel成员,并运行代码在那里以及更新“真正的”价值(私人会员)。当然你需要匹配的getter。

+0

我还是有点困惑......谁打电话给二传手? – mjeffw

+0

当您选择新值时,该框架会执行此操作。 –

+0

我知道我可能很密集,但是像这样? SelectionModel _selectModel = new SelectionModel(); SelectionModel get selectModel {return _selectModel; } set selectModel(SelectionModel model){ _selectModel = model; _selectModel.selectionChanges.listen(updateSelection); } 如果是这样,它不工作。响应于更改选择,setter不会被调用。 – mjeffw