Javascript Angularjs:在使用ngChange时,如何获取列表中的项目?

Javascript Angularjs:在使用ngChange时,如何获取列表中的项目?,javascript,angularjs,angularjs-ng-change,Javascript,Angularjs,Angularjs Ng Change,在这个小示例中,我试图得到刚刚更改的项,是否应该使用某种上下文?我希望它会像只提到$this一样简单,但这似乎不起作用 <html ng-app> <head> <script src="https://code.angularjs.org/1.2.9/angular.min.js"></script> <script> function myController($scope) { $scope.items = [

在这个小示例中,我试图得到刚刚更改的项,是否应该使用某种上下文?我希望它会像只提到$this一样简单,但这似乎不起作用

<html ng-app>
<head>
<script src="https://code.angularjs.org/1.2.9/angular.min.js"></script>
<script>
  function myController($scope) {
    $scope.items = [
      { id: 1, name: "First" },
      { id: 2, name: "Second" },
      { id: 3, name: "Third" }
    ];

    $scope.test = function() {
        // How do I get the object in the list related to the change i did?
        // I.e. "{ id: 2, name: "Second" }" for the second item.
    };
  }
</script>
</head>
<body>
<div ng-controller="myController">
<table>
  <tbody ng-repeat="item in items">
    <tr>
      <td>{{ item.id }}</td>
      <td><input type="text" ng-model="item.name" ng-change="test()"/></td>
    </tr>
  </tbody>
</table>
</div>
</body>

函数myController($scope){
$scope.items=[
{id:1,名称:“First”},
{id:2,名称:“Second”},
{id:3,名称:“第三”}
];
$scope.test=函数(){
//如何获取列表中与所做更改相关的对象?
//即第二项为“{id:2,名称:“Second”}”。
};
}
{{item.id}
看看这个

html

<div ng-app='myApp' ng-controller="myController">
<table>
  <tbody ng-repeat="item in items">
    <tr>
      <td>{{ item.id }}</td>
      <td><input type="text" ng-model="item.name" ng-change="test(item.name)"/></td>
    </tr>
  </tbody>
</table>
</div>

看到这个了吗ng change=“test(item)”@MichaelLo谢谢!真不敢相信我错过了!对于这个愚蠢的问题,我很抱歉:(我也看到了@MichaelLo的评论。多亏了你们两个!真不敢相信我错过了…:)我不能向上投票,投票率低(这是我的第一个问题)。我只能接受它的回答!
var app = angular.module('myApp', []);
app.controller('myController', function ($scope) {
    $scope.items = [
      { id: 1, name: "First" },
      { id: 2, name: "Second" },
      { id: 3, name: "Third" }
    ];

    $scope.test = function(item) {
        alert(item);
    };
});