Mihai Gota
Mihai Gota

Reputation: 97

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?

Upvotes: 0

Views: 586

Answers (2)

Natiq
Natiq

Reputation: 416

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

Upvotes: 1

Kishan Mundha
Kishan Mundha

Reputation: 3141

use $scope.org.selectedChannels in controller to access select box value

Upvotes: 0

Related Questions