0

I am transitioning from jquery to angularjs. I am trying to develop a small app in SPA style. Left side is the menu that controls the content on the right side. Left side menu has its own controller. When the user selects a checkbox and clicks on 'Go', the checkbox value should be passed to the controller that controls the right side content. Here is the link to the app. Below are the issues I have.

1)I am stumped on a simple problem of accessing checked values of a checkbox. How do I access values of checked checkboxes. The checboxes are on left side menu, and I am using ng-model to currently access the values as below

index.html

<div id="searchOne">
      <ul>
        <li ng-repeat="searchOneCB in main.checkBoxOneData">
          <input type="checkbox" name="firstSearch" id="firstSearch_{{searchOneCB.code}}" ng-model="main.selected[searchOneCB.code]" />
{{searchOneCB.description}}
        </li>
      </ul>

      <button class="btn btn-primary" style="width:80px;margin-right: 10px" ng-click="main.submit()">
          Go
      </button>
</div>

MainCtrl.js to access the checkbox value.

main.submit = function() {      
  console.log(main.selected);
}

The values are now in the form of an array as below

[BBBB: true, AAAA: true].

Is this the right way to access the values? What is the best way to retrieve only the checked checbox values?

2) Another question is, once I get the list of checked checkboxes values, how can I pass them to the contentCtrl.js that controls the content on right side?

DG3
  • 5,070
  • 17
  • 49
  • 61

1 Answers1

0

You should inject the controller into the controller you want to use. The answer has already been answered here is the link.

How do I inject a controller into another controller in AngularJS

Community
  • 1
  • 1
Abdullahi
  • 134
  • 8