Front-end - string conversion problem when using angularjs
巴扎黑
巴扎黑 2017-05-15 16:51:59
0
2
521

I want to use angular to make an automatic adder, the code is as follows

    <input type="text" ng-model="add1">
    <input type="text" ng-model="add2">
    <p>total={{add1+add2}}</p>

This code simply connects strings. I tried to use parseInt(add1) parseInt(add2) but it didn’t work. I don’t know if Angular has any method to convert characters into numerical values.

巴扎黑
巴扎黑

reply all(2)
Peter_Zhu
 <p>total={{add1 * 1 + add2 * 1}}</p>
阿神

You can add the corresponding function in $scope

$scope.parseInt = parseInt;

Then you can use it

parseInt(add1) + parseInt(add2)
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template