Angelina Angelina - 6 months ago 25
AngularJS Question

Storing strings in array as user selects checkbox

I just started using

and am trying to learn how to insert strings in array when user clicks checkbox and later access these values.

This is what I have so far:

<md-button class="toolbar-button" ng-click="removePlan()">
<md-list-item ng-repeat="plan in plans">
<md-checkbox ng-model="plansSelected[plan._id]"> </md-checkbox>


$scope.plansSelected = []
$scope.removePlan = function () {
for (var plan in $scope.plansSelected) {
if ($scope.plansSelected[plan] === true) {
projectResource.removePlan(plan).then(function (data) {
if (data.success) {


resource.removePlan = function (planId) {
return $http.delete(getPlanUrl(planId)).then(processResponse, processError)

function getPlansUrl () {
return getProjectUrl() + '/plans'

function getPlanUrl () {
return getPlansUrl() + '/' + $route.current.params.planId

In debugger this is how my array looks like:

$scope.plansSelected: Array[0]

I am checking if user removed selection from the checkbox and if the value is true then take that plan._id and pass in the loop to

Does anyone see what I am doing wrong, because this is not working.


Please be more specific what "this is not working" means - it's hard for us to detect that without being able to run it.

I can see that your use of $scope.plansSelected as an empty array is wrong. I would dispense with that and do it like this:

<md-list-item ng-repeat="plan in plans track by $index">
    {{}} <md-checkbox ng-model="plans[$index].selected"> </md-checkbox>

This basically adds a 'selected' attribute to your plans array, and make it easier for you to iterate over the plans array and pull out the ones you want.