将字符串转换为数字角度 2 单向绑定 [英] convert string to number angular 2 one way binding

查看:20
本文介绍了将字符串转换为数字角度 2 单向绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将字符串转换为数字 angular 2 单向绑定

convert the string to number angular 2 one way binding

[longitude]="loc.location.lng">

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)
}

调用模板中的函数

[longitude]="ConvertString(loc.location.lng)"

这篇关于将字符串转换为数字角度 2 单向绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆