我对AngularJS和基本数学有疑问。从Firebase中选取数据后,我想添加它们。
这是我的代码:
$scope.project.$on('loaded', function(value) {
console.log(value); // data loaded from Firebase
console.log(value.name); // subset of the returned value
angular.isNumber(value.firstmatch);
angular.isNumber(value.secondmatch);
$scope.project.points = ((value.firstmatch) + (value.firstmatch));
然后输出11。是的,firstmatch值为1。
谢谢!
因此,您的数据为您提供了字符串,只需将它们转换为数字即可:
$scope.project.$on('loaded', function(value) {
console.log(value); // data loaded from Firebase
console.log(value.name); // subset of the returned value
//angular.isNumber(value.firstmatch);
//angular.isNumber(value.secondmatch);
$scope.project.points = parseInt(value.firstmatch, 10) + parseInt(value.firstmatch,10);
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句