1

I have the following array:

$scope.profile.preferencias = [7,5,3,8,4];

EDIT My Category array looks like this:

[
  {
    "id": 2,
    "descricao": "Entomologia",
    "dataCriacao": "0001-01-01T00:00:00",
    "isActive": true,
    "isFixed": true
  },
  {
    "id": 3,
    "descricao": "Fisiologia",
    "dataCriacao": "0001-01-01T00:00:00",
    "isActive": true,
    "isFixed": true
  }
]

My ion-checkbox looks like this:

<ion-checkbox ng-repeat="category in categories | toArray | orderBy:'descricao'" name="group" ng-model="profile.preferencias[category.id]">{{category.descricao}}</ion-checkbox>

The output selected is:

{
   "7": true,
   "5": false,
   "3": true
}

How can i sent only the number to my json, so it will save like the $scope above, and when the page is reloaded, the checkboxes comes back checked?

Thanks!

5
  • Could you please share your $scope.categories array? Commented Jun 1, 2016 at 5:32
  • Hi, added the category array, thanks Commented Jun 1, 2016 at 5:36
  • You need a number array [selected category Ids] right? Commented Jun 1, 2016 at 5:47
  • Correct, and then i'll save it like the $scope.profile.preferencias, but i need the checkboxes to be checked when reloading the page Commented Jun 1, 2016 at 5:53
  • Can you create a plunker/Fiddle example? Commented Jun 1, 2016 at 6:01

1 Answer 1

1

i am using same things in my app.

<div ng-repeat="day in days" class="week_days">
        <ion-checkbox ng-model="day.select" style="border:none">{{day.name}}</ion-checkbox>
</div>

and JSON data is

$scope.days = [{
            "id": 1,
            "name": "Mon",
            "select": true
        }, {
            "id": 2,
            "name": "Tue",
            "select": true
        }, {
            "id": 3,
            "name": "Wed",
            "select": true
        }, {
            "id": 4,
            "name": "Thu",
            "select": true
        }, {
            "id": 5,
            "name": "Fri",
            "select": true
        }, {
            "id": 6,
            "name": "Sat",
            "select": true
        }, {
            "id": 0,
            "name": "Sun",
            "select": true
        }];

the above $scope variable is default checkbox is selected. if you want not default checkbox is selected then changed "select":false".

Thanks,

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.