1
我正在用HTML + CSS + AngularJS制作一个简单的计算器。一切正常,但我想添加一个SquareRoot函数。 这是一些代码:AngularJS平方根
function _solve(){
switch(_state) {
case 'ADD':
_total += parseFloat($scope.console);
$scope.console = 0;
break; //similar for the rest of the operations
$scope.add = function() {
_solve();
_state = 'ADD';} //this is how i call the function.
这是我的Sqrt的想法,但我不认为这是很好的:
$scope.getSqrt = function() {
$scope.console = (parseFloat($scope.console) * Math.Sqrt).toString();}
http://www.tutorialspoint.com/javascript/math_sqrt.htm你能不能做这样的事情? –
虽然有可能将数学注入与Angular一起使用,但它并不是处理该问题的角度方式。在Angular中,你会创建自己的平方根函数(使用牛顿方法将是最好的) – snaplemouton