wht*_*evn 23 javascript angularjs
我有一个显示控制器和一个管理控制器.在我的显示控制器中,我有一个下拉选择器,其中包含已选择的项目列表.
我可以获取显示区域下拉列表来更新列表,添加项目在管理控制器中添加,但我无法弄清楚如何选择下拉列表中的最新项目.
<div ng-controller="MyDisplayCtrl">
<select ng-model="item" ng-options="i.name for i in items">
</select>
</div>
Run Code Online (Sandbox Code Playgroud)
我已经做了一个jsfiddle来说明我的情况.但最终,我的问题是如何将ng-model ="item"绑定到由服务更新的数据源.
wht*_*evn 15
好吧,看起来我已经找到了一个非常令人满意的答案.
我通过控制器暴露了存储对象本身
function MyDisplayCtrl($scope, ItemStore) {
$scope.items = ItemStore.items;
$scope.item = ItemStore.currentItem;
// expose the itemstore service to the dom
$scope.store = ItemStore
$scope.getItem = function(){
return(ItemStore.currentItem);
}
}
Run Code Online (Sandbox Code Playgroud)
然后直接解决currentItem
<div ng-controller="MyDisplayCtrl">
<select ng-model="store.currentItem" ng-options="i.name for i in items">
</select>
</div>
Run Code Online (Sandbox Code Playgroud)
http://jsfiddle.net/whtevn/Cp2RJ/3/
| 归档时间: |
|
| 查看次数: |
41159 次 |
| 最近记录: |