【发布时间】:2015-05-18 19:57:07
【问题描述】:
我正在使用 HTML + CSS + AngularJS 制作一个简单的计算器。一切正常,但我想添加一个 SquareRoot 函数。 这是一些代码:
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();}
【问题讨论】:
-
tutorialspoint.com/javascript/math_sqrt.htm这样的事情你能不做吗?
-
虽然可以注入 Math 以与 Angular 一起使用,但这不是 Angular 处理问题的方式。在 Angular 中,您将创建自己的平方根函数(最好使用牛顿法)
标签: html css angularjs square-root