0

i have list of data displayed in table. As i click any td i display the list of selected values in another table.The Problem is if i select more than one row then in addition to the previous record next selected value should also be displayed but as per my code that do not happen.Should i use checklist? Or changes can be done in the existing one.code is as follows:

<table class="table table-hover" style="width:300px;">
<tr ng-repeat="work in jointworkdata">

  <td ng-click="selectedVal(tab,work.jointwork_name)">{{work.jointwork_name}}</td>
  </tr>

and display table is:

<table   class="table table-hover"><tr>
<td >{{selectedData}}</td></tr>

code in controller is:

$scope.selectedVal = function(tab,val) {

        if(tab==1)
        {

         $scope.selectedData=val;}
         };

The output gives one record at a time and not all selected since fucntion is getting called on click.

1 Answer 1

1

You can accomplish this with 2 way binding https://docs.angularjs.org/guide/databinding .

Lets say you have a simple Controller that has the primary data to display and then a variable that collected the ones the user is adding on.

app.controller = function($scope) {
   $scope.data = [1,2,3,4];
   $scope.data2 = new Array();

   $scope.add = function(item) {
       $scope.data2.push(item);
   };
};

Now in the view its simple as displaying both of them

<tr ng-repeat="item in data">
  <td ng-click="add(item)">{{ item }}</td>
</tr>

...

<tr ng-repeat="item2 in data2">
  <td>{{ item2 }}</td>
</tr>

Two way binding will take care of automatically rerunning that ng-repeat if any new items are added to the data2 array.

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.