myApp.controller('incomeController', ['$scope', function($scope) {
$scope.pay = 0;
$scope.hours = 0;
$scope.tax=0.19297;
$scope.total = function() {
return $scope.pay * $scope.hours;}
$scope.taxTotal = function ($scope){
return($scope.total * $scope.tax);}
$scope.afterTaxTotal = function ($scope){
return($scope.total - $scope.taxTotal);}
}]);

<div ng-app="myApp" ng-controller="incomeController">
<h2>Income Calculator</h2>
<br>
<br>
<p16>Pay Rate: </p16><input type="number" ng-model="pay">
<p15> Hours worked:</p15> <input type="number" ng-model="hours">
<br>
<br>
<br>
<p><b>Total Before Taxes:</b> {{ total() | currency : $ }}</p>
</div>
<p><b>Total Taxes :</b> {{ taxTotal() | currency : $ }}</p>
<p><b>Total After Taxes:</b> {{ afterTaxTotal() | currency : $ }}</p>
&#13;
我正在尝试做一个简单的代数方程。
答案 0 :(得分:0)
您还需要使用控制器内的括号来调用函数。
function MyCtrl($scope) {
$scope.pay = 5;
$scope.hours = 10;
$scope.tax= 0.19297;
$scope.total = function() {
return $scope.pay * $scope.hours;
};
$scope.taxTotal = function () {
return $scope.total() * $scope.tax;
};
$scope.afterTaxTotal = function () {
return $scope.total() - $scope.taxTotal();
};
}
示例:http://jsfiddle.net/m62f70mk/5/
此外,您不需要传递$ scope,它可以在您的函数中使用。你的段落标签是怎么回事? ?