我的 HTML
<body ng-app="myApp" ng-controller="myCTRL">
<form class="my-form" ng-repeat="item in items" novalidate>
<h4>{{item.number}}</h4>
<input type="text" ng-model="item.hed"><br>
<input type="text" ng-model="item.subhed">
</form>
</body>
我的JS:
var app= angular.module("myApp",[]);
app.controller("myCTRL",function($scope,$http){
$scope.items= [
{
number: chartNumber,
hed: '',
subhed: ''
}
];
});
当我在 input
标签中输入内容时,我想要 console.log()
item.number
值。如何使用 AngularJS v1.6.1 执行此操作?
最佳答案
使用 ng-change 指令检测输入值的任何变化
<body ng-app="myApp" ng-controller="myCTRL">
<form class="my-form" ng-repeat="item in items" novalidate>
<h4>{{item.number}}</h4>
<input type="text" ng-model="item.hed" ng-change="inputChange(item)"><br>
<input type="text" ng-model="item.subhed" ng-change="inputChange(item)">
</form>
</body>
JS
var app= angular.module("myApp",[]);
app.controller("myCTRL",function($scope,$http){
$scope.items= [
{
number: chartNumber,
hed: '',
subhed: ''
}
];
$scope.inputChange = function(item) {
console.log(item.number);
}
});
关于javascript - 如何从 ngRepeat 中的文本输入获取项目编号?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41324385/