Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Function 用AngularJS进行实时计算_Function_Angularjs - Fatal编程技术网

Function 用AngularJS进行实时计算

Function 用AngularJS进行实时计算,function,angularjs,Function,Angularjs,一般来说,我对Angularjs和MVVM模型非常陌生。我正在尝试构建一个计算器应用程序,它可以像Excel电子表格那样工作。IE更新一个单元格会导致所有依赖单元格也更新 到目前为止,我的代码是这样的 <div ng-app=""> <div ng-controller="calculations"> <input type="number" name="staff" ng-model="staff" id="staff" ng-change="cha

一般来说,我对Angularjs和MVVM模型非常陌生。我正在尝试构建一个计算器应用程序,它可以像Excel电子表格那样工作。IE更新一个单元格会导致所有依赖单元格也更新

到目前为止,我的代码是这样的

<div ng-app="">


<div ng-controller="calculations">

    <input type="number" name="staff" ng-model="staff" id="staff" ng-change="change('C3')"  />

    <input type="hidden" name="budget" ng-model="budget" ng-change="change('C6')" placeholder="budget" />

    <input type="text" name="total" ng-model="total" ng-change="change('C8')" />

</div>

我不知道如何添加一个连接函数,当cell=C6时(它应该在我的第一个函数中设置$scope.budget),然后$scope.total=$scope.budget/$scope.staff;依此类推,直到我的所有字段都具有动态值。我的想法是,我不想做提交或点击开始计算,我想做他们的飞行,这就是为什么我选择角,因为我的理解,这是它做得很好。想法?

是否需要对“总计”进行编辑?我认为,如果“staff”和“budget”是唯一可编辑的字段,而“total”是从这些字段中动态计算出来的(但本身不可编辑),那么这将是非常容易的。不要担心哪个单元格触发了
$scope.change()
,只需运行
total
的calcs,这比我想象的要容易得多,如果你想把你的评论作为回答,我会接受的:D谢谢
function calculations($scope) {







$scope.change = function (cell) {

    if (cell == 'C3') {
        $scope.budget = $scope.staff * 35000;

    }






};

}