Javascript 如何在ng中单独重复$watch输入并将结果附加到angular js中的特定行?
我有两个输入字段b_price和s_price在ng repeat中。我需要观察这两个模型中的变化并添加估计值。我的代码片段: htmlJavascript 如何在ng中单独重复$watch输入并将结果附加到angular js中的特定行?,javascript,angularjs,indexing,angularjs-ng-repeat,angularjs-watch,Javascript,Angularjs,Indexing,Angularjs Ng Repeat,Angularjs Watch,我有两个输入字段b_price和s_price在ng repeat中。我需要观察这两个模型中的变化并添加估计值。我的代码片段: html {{list.symbol} {{list.todays{u rate} {{估计值} js var-app=angular.module('testthis',[]); app.controller('testCtrl',函数($scope,$http){ $scope.testList={}; $scope.testList.lists=[{id:1,
{{list.symbol}
{{list.todays{u rate}
{{估计值}
js
var-app=angular.module('testthis',[]);
app.controller('testCtrl',函数($scope,$http){
$scope.testList={};
$scope.testList.lists=[{id:1,符号:“assas”,总计:123},
{编号:2,文号:“as”,总数:103}];
对于(var i=0;i
<body ng-app="testthis" ng-controller="testCtrl">
<table>
<tr ng-repeat="list in testList.lists track by $index">
<td>{{list.symbol}}</td>
<td>{{list.todays_rate}}</td>
<td><input type="text" ng-model="testList.b_price"></td>
<td><input type="text" ng-model="testList.s_price"></td>
<td>{{estimated}}</td>
</tr>
</table>
</body>
var app = angular.module('testthis', []);
app.controller('testCtrl', function($scope, $http) {
$scope.testList ={};
$scope.testList.lists = [{id: 1,symbol: "assas", total: 123},
{id: 2,symbol: "as", total: 103}];
for (var i=0; i<$scope.testList.lists.length; i++){
$scope.estimated =0;
$scope.$watch('testList.b_price + testList.s_price', function() {
console.log('watch');
if ($scope.testList.b_price){
console.log('as');
$scope.testList.s_price = "";
$scope.estimated = 100 - $scope.testList.b_price;
}else if ($scope.testList.s_price){
$scope.testList.b_price = "";
$scope.estimated = $scope.testList.s_price - 100;
}
});
}
});