convert string to number angular 2 one way binding

故事扮演 提交于 2019-12-05 20:03:08

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;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!