Mihai Gota Mihai Gota - 1 month ago 9
AngularJS Question

How to access in controller an angular model inside another model?

Every organization has multiple channels. Foreach organization, I display a multiple select box with the channels as options.

<div class="col-sm-9">
<div class="row">
<div class="col-sm-4" ng-repeat="orgModel in selectedOrganizations.selectedOrganizations">
<div class="box">
<div class="box-header"><h3>{{orgModel.name}}</h3></div>
<div class="box-divider m-a-0"></div>
<ul class="list no-border p-b">
<li class="list-item">
<div class="list-body">
<select multiple name="singleSelect" class="form-control input-c" id="singleSelect" ng-model="org.selectedChannels" ng-options="channel.name for channel in orgModel.channels" ng-show="item.editing">
</select>
</div>
</li>
</ul>
</div>
</div>
</div>
</div>


Where and how I can access the
org.selectedChannels
in the controller?

Answer

In order to assign selected channels to each organization you must use ng-repeat variable in ng-model of select element.

ng-model="orgModel.selectedChannels"

After that, you can access selected channels of each organization by index of organization:

$scope.selectedOrganizations.selectedOrganizations[0].select‌​edChannels