8

I have a simple table with three rows and two values for each row - date and state:

<tbody>
   <tr>
      <td>Red</td>
        <td class="lastModified">{{item.redDate}}</td>
        <td class="status"> 
            <select id ="red" class="form-control" ng-change="update();" ng-model="item.redStatus">
              <option value="" disabled="" selected="" class="ng-binding">Please select the value</option>
              <option ng-selected="step.value === item.redStatus"  ng-repeat="(key, step) in steps">{{ step.title }}</option>
            </select>
       </td>
   </tr>
   <tr>Green</tr>
   <tr>
     ....
   </tr>                    
</tbody>

So, simple date and status values for red, green and blue. One in dropdown - status, the second - just output date.

On change the select value - i need to update the date with today's date.

 `$scope.item.redDate = new Date();`

Is it possible to have one function like ng-change="change();" Can't send with ng-change the ID...

7
  • 1
    Why you can't? You can send ID as argument in update() method like ng-change = "update('red')" what is the issue actually? Commented Apr 1, 2015 at 17:19
  • Mmm... yes, and how then i could update the date? if it's $scope.item.redDate? In JS i'll d something like var date = id +'Date' Commented Apr 1, 2015 at 17:23
  • 1
    Like this $scope.item[id+'Date'] = new Date(); Commented Apr 1, 2015 at 17:32
  • So, function should be like $scope.update= function(id){ alert('id' + id); $scope.item[id+'Date'] = new Date(); }; But alert say, that Id is undefined . ng-change="update(id);" Commented Apr 1, 2015 at 18:09
  • 1
    Oh you are sending direct id. I thought you would pass the color name like ng-change="update('red');" Commented Apr 1, 2015 at 18:14

1 Answer 1

15

Special thanks to Samir Das with help to find the solution ng-change="update(id);":

<select id ="red" class="form-control" ng-change="update(id);" ng-model="item.redStatus">
          <option value="" disabled="" selected="" class="ng-binding">Please select the value</option>
          <option ng-selected="step.value === item.redStatus"  ng-repeat="(key, step) in steps">{{ step.title }}</option>
 </select>

Here is the controller:

$scope.update = function(id){
    id = event.target.id;
    $scope.item[id+'Date'] = new Date();
 };
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.