I have tried using $watch to get the data entered in the
<input type="text" ng-show="expense.done" ng-model="spentamount" size="30"
placeholder="Enter the amount">
javascript:
$scope.spentAmount = function() {
angular.forEach($scope.expenses, function(expense) {
if(expense.done){
$scope.$watch('spentamount',function () {
console.log($scope.spentamount);
});
}
});
//return amount;
};
HTML:
<label for="spentby">Spent by</label>
<ul class="unstyled">
<li ng-repeat="expense in expenses">
<input type="checkbox" ng-model="expense.done">
<span>{{expense.text}}</span>
<input type="text" ng-show="expense.done" ng-model="spentamount" size="30"
placeholder="Enter the amount"><span>{{addExpenseAmount()}}</span>
</li>
</ul>
<form ng-submit="addExpense()">
<input type="text" ng-model="expenseText" size="30"
placeholder="Enter the names">
<input class="btn-primary" type="submit" value="Add">
</form><br>
<label for="amountspent">Amount spent(Rs)</label>
<span>{{spentAmount()}}</span><br>
But console.log($scope.spentamount)
says 'undefined'
Is my usage of $watch correct?
Please advice