Masinde Muliro Masinde Muliro - 10 months ago 115
Javascript Question

Binding dynamic checkbox in angular.js

I have a list of options pulled from the database via json based on product selection in angular.js

Here's a sample code:

<ion-checkbox ng-repeat="extra in extras" ng-model="order.extras" checklist-value="{{ }}"><strong>{{ }}</strong></ion-checkbox>

I want a user to be able to select multiple extras but can't seem to be able to bind these selections.


I think it could work with ng-model="order.extras[]" then you can track the checked extras in order.extras.

Please have a look at the demo below or at this jsfiddle.

angular.module('demoApp', ['ionic'])
	.controller('mainController', mainController);
function mainController($scope) {
	$scope.order = {};
	$scope.extras = [
        id: 0,
        name: 'first'
        id: 1,
        name: 'second'
        id: 2,
        name: 'third'
<link href="" rel="stylesheet"/>
<script src=""></script>
<script src=""></script>
<div ng-app="demoApp" ng-controller="mainController">
    <ion-checkbox ng-repeat="extra in extras" ng-model="order.extras[]" checklist-value="{{ }}"><strong>{{ }}</strong></ion-checkbox>
current order: {{order}}