我有一个ng-repeat
-ed 表格行,里面有一对 angular select
s:
<div ng-controller="midiCtrl" id="midi-ctrl">
[...]
<tr ng-repeat="plugin in plugins">
<td><strong>{{plugin.name}}</strong></td>
<td>
<select class="span1" ng-model="selectedChannel" ng-options="item.ID as item.Title for item in channels">
</td>
<td>
<select class="span2" ng-model="selectedDevice" ng-options="item.ID as item.Title for item in devices">
</td>
</tr>
[...]
</div>
控制器是:
app.controller('midiCtrl', function ($scope, pluginDisplayedWindows) {
$scope.plugins = pluginDisplayedWindows.pluginsDisplayed; // An object
$scope.channels = [
{ID: 'all', Title: 'All'},
{ID: '0', Title: '1'},
{ID: '1', Title: '2'},
{ID: '2', Title: '3'}
];
$scope.devices = [
{ID: '0', Title: 'Device A'},
{ID: '1', Title: 'Device B'},
{ID: '2', Title: 'Device C'},
{ID: '3', Title: 'Device D'},
];
});
Now, I know that when one of the selects is selected, the corresponding object is set on the ng-model scope variable ( $scope.selectedChannel
or $scope.selectedDevice
), but obviously it is set in the corresponding ng-repeat child scope .
如何在控制器中访问子范围?我想在用户按下按钮时保存所有选择,但是如果我尝试在midiCtrl
控制器中执行此操作,我将无法访问由ng-repeat
.