totalbalancetemp = (Number(this.balance)) + (Number(this.pastAmount));
My totalbalancetemp
is returning undefined whereas this.balance
is equal to 34 and this.pastAmount
is equal to 23.
I have this in controller and displaying totalbalancetemp
using exp in html
-
if totalbalancetemp is a property of the component. then shouldn't you call it by this.totalbalancetempThirueswaran Rajagopalan– Thirueswaran Rajagopalan2017年03月08日 08:28:42 +00:00Commented Mar 8, 2017 at 8:28
5 Answers 5
Supply the proper type.
let totalbalancetemp:number = balance + pastAmount
This will throw an error, because you are now guaranteeing that totalbalancetemp
will be a number
.
The type String is not assignable to type 'number'
Try the following:
let balance:string = '34',
pastAmount:string = '23',
totalbalancetemp:number = 0
totalbalancetemp = Number(balance) + Number(pastAmount)
alert(totalbalancetemp)
1 Comment
totalbalancetemp = (Number(this.balance)) + (Number(this.pastAmount));
please try this it should work
totalbalancetemp:number = (+this.balance) + (+this.pastAmount);
Comments
var totalbalancetemp = null; this.balance = 34; this.pastAmount = 23;
totalbalancetemp = (Number(this.balance)) + (Number(this.pastAmount));
alert(totalbalancetemp);
-->totalbalancetemp - Define Variable (or) any type
Comments
totalbalancetemp should be replaced by this.totalbalancetemp if it's part of the angular 2 component
Comments
Do a +this.balance
in the .ts file or this.balance*1
or this.balance/1
on in the template file.