1

I have a tables array consist of two objects. Each object having the tablename. I use ng-repeat for the checkbox. When I select the checkbox selected object will push into array [tablelist] and the array will use for drodownlist.

$scope.tables=[{"tabelname":"t1},{{tabelname:t2}}]
$scope.tablelist=[]

this is my html code

<div ng-repeat="table in tables">
    <span class="col-sm-1">
    <input type="checkbox" ng-model="table.tablename" class="form-group">{{table.tablename}}</span>
</div>

<select ng-options="table.tablename as table.tablename for table in  tablelist></select>
2
  • Your code isn't valid JavaScript. Commented May 3, 2016 at 6:16
  • $scope.tables but you are referring to $scope.table? tablename vs tabelname ..? more? Commented May 3, 2016 at 6:18

2 Answers 2

1
<div ng-repeat="table in tables">
    <span class="col-sm-1">
    <input type="checkbox" ng-click="saveData($index)" ng-model="table.tablename" class="form-group">{{table.tablename}}</span>
</div>

<select ng-options="table.tablename as table.tablename for table in  tablelist></select>

In your controller:


$scope.saveData = function(index) {
if(table.tablename)
    $scope.tablelist[index] = $scope.tables[index];
};

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

Comments

0
<div ng-repeat="table in tables">
<span class="col-sm-1">
<input type="checkbox" ng-click="saveData(table.tablename)" ng-model="table.tablename" class="form-group">{{table.tablename}}</span></div><select ng-options="table.tablename as table.tablename for table in  tablelist></select>

Simple pass Your Table name to the saveData func. then push this name to array

$scope.saveData = function(tbaleName) {$scope.tablelist.push(tableName)}

Make Sure that there is no existing value

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.