AngularJS checkbox ng-repeat and seleted objects?

I am trying to do it in proper way with less pain, but i can’t figure out how to deal with ng-model and binding it to the selected list etc..and moreover i need to populate that list in later time and keep selected objects in it.

categories = [ { "name": "Sport", "id": "50d5ad" } , {"name": "General", "id": "678ffr" } ]

    <span ng-repeat="category in categories">
      <label class="checkbox" for="{{category.id}}">
        <input type="checkbox" value="{{category.id}}" ng-model="??" ng-click="??" name="group" id="{{category.id}}" />
        {{category.name}}
      </label>
    </span>

I have to override the categories each time the list is populated since it will be pull out form server. So i quess i need to have arrays and the second one will hold the selected objects?

If I am right, how do I preselected checkboxes?

Do I need ng-click in order call custom function to store the selected object in the other array?

Do i need ng-model in check box? And what for?

What is the proper-way with less pain?

Thank you.

How to push objects in AngularJS between ngRepeat arrays

So I’m new to AngularJS and I’m trying to build a very simple list app, where I can create an ng-repeat item list and then push a selected item into another ng-repeat list. Although my problem seems t

AngularJS filter null key:value row from ngRepeat list – data stored in objects within array

I have my data stored in an array of objects and it is being used to create a list on the page with ngRepeat. The problem is that some of the values within the object are null and I want to hide just

AngularJS ngRepeat element removal

There are quite a few questions on how to implement item removal inside ngRepeat directive, and as I figured out, it comes down to using ngClick and triggering some remove function passing it item’s $

Angularjs: ngRepeat and directive

I am trying to make some reusable countdown widgets. Works well with a static content, but when i’m trying to add them on the fly, my directive doesn’t understand the variables inside the ngRepeat. Ma

angularjs bind template as item inside ngrepeat

I have a special situation in the angularjs, i cant template inside ngRepeat that template is a parameter of item <tr data-ng-repeat=item in items > <td data-ng-repeat=column in columns n

Angularjs UI collapse in ngRepeat

I am trying to embed some collapsible panels in a ngRepeat. This is what I have: <div class=panel panel-default ng-repeat=element in elements> <div class=panel-heading> {{element.nam

AngularJs sort object in ngRepeat

I’m using AngularJs and found a problem in ordering properties of a hash object in a template. My object is like: function TestCtrl($scope){ $scope.week = {‘MONDAY’: [‘manuel’], ‘TUESDAY’: [], ‘WEDNE

AngularJS Transclusion of ngRepeat inside custom directive

I am trying to build a custom directive that rearrange its content as a grid. I want to transclude the result of an ngRepeat directive and then reorder the resulting elements. The problem is when I ca

angularjs ngRepeat table, get height wrong

I have a problem of getting a ngRepeat table’s height when page loaded I’m trying to get the height when event $viewContentLoaded fires, but the table’s height equals the height of the title bar of th

Angularjs animate – disable for some ngRepeat

Is it possible somehow completely disable animation for some ngRepeat directive usage? I don’t have any animations defined yet, but when ngAnimate module is loaded, automaticaly delays removing DOM el

Answers

I have to override the categories each time the list is populated since it will be pull out form server. So i quess i need to have arrays and the second one will hold the selected objects?

Yes, since it is a list you can/should use arrays. The information about the selected items/objects should be stored on your scope model (example below).

If I am right, how do I preselected checkboxes?

Save the ID’s of the selected options/checkboxes on your model and let the ng-model do the rest.

Do I need ng-click in order call custom function to store the selected object in the other array?

No, you don’t need it, ng-model is enough.

Do i need ng-model in check box? And what for?

Yes, you need it. The ng-model is responsible for storing the selected options on your model and for making the (‘pre-‘)selection automatic.

jsfiddle http://jsfiddle.net/bmleite/PQvQ2/