convert the string to number angular 2 one way binding
[longitude]="loc.location.lng">
loc.location.lng is string i need to convert them to number.but still not working as I expect. In interpolation it's working but in this not working. Thanks
Make a function which convert the value to float as its location and return the value.
ConvertString(value){
return parseFloat(value)
}
Call the function in template
[longitude]="ConvertString(loc.location.lng)"
You could also force the cast by trying this:
[longitude]="+loc.location.lng"
Since you havent provided your source code, its difficult to help you - but if you define longitude as a number, then Angular should cast the string value automatically during binding.
@Input() longitude: number;
来源:https://stackoverflow.com/questions/45860349/convert-string-to-number-angular-2-one-way-binding