I'm learning angular js and got stuck in the following code:
<div ng-app="calculate">
Amount: <input type='text' data-ng-model='amount' name = 'amount' placeholder = 'Enter amount' >
Charge: <input type='text' name = 'charge' ng-bind="charge" value="{{ amount | serviceFilter }}" >
Total: <input type='text' value= " {{(amount)+ (amount | serviceFilter)}}" name = 'total' >
</div>
<script>
angular.module('calculate', [])
.filter('serviceFilter', function( ){
return function(amount){
if(angular.isUndefined(amount)){
charge = '0';
}else{
if(isNaN(amount)){
charge = 'Invalid Data !!!';
}else{
if(amount < 1000){
charge = '200';
}else{
charge = '500';
}
}
}
return charge;
};
});
</script>
When I enter the amount. I get appropriate charge. But I can't add the amount and charge get the total value. Let's say:
Amount: 1200
Charge: 500
Total : 1700
I need to get 1700 but instead I get
Total: 1200 500
Also I want to know if this is the appropriate way or there is any other better way to do this. Thankyou