私のコードでどこが間違っていましたか?ボタンをクリックすると、最初の番号と2番目の入力番号が表示されます。モデルをanglejsのコントローラ関数に渡す
app.controller('AddSum', ['$scope', function ($scope) {
$scope.sum = 0;
$scope.add = function (fnumber, snumber) {
$scope.a = $scope.fnumber;
$scope.b = $scope.snumber;
$scope.sum = $scope.a + $scope.b;
};
}]);
Htmlの
<table ng-controller="AddSum">
<tr>
<td>Enter First Number:</td>
<td><input ng-model="fnumber"></td>
</tr>
<tr>
<td>Enter Second Number:</td>
<td><input ng-modle="snumber" /></td>
</tr>
<tr>
<td><button ng-click="add()">SUM</button></td>
<td><p>Sum:{{sum}}</p></td>
</tr>
</table>
そのが機能していない、変更されたコードを参照してください。
app.controller('AddSum', ['$scope', function ($scope) {
$scope.sum = 0;
$scope.add = function (fnumber,snumber) {
$scope.a = $scope.fnumber;
$scope.b = $scope.snumber;
$scope.sum = parseInt($scope.a) + parseInt($scope.b);
};
}]);
<table ng-controller="AddSum">
<tr>
<td>Enter First Number:</td>
<td><input ng-model="fnumber"></td>
</tr>
<tr>
<td>Enter Second Number:</td>
<td><input ng-model="snumber" /></td>
</tr>
<tr>
<td><button ng-click="add(fnumber,snumber)">SUM</button></td>
<td><p>Sum:{{sum}}</p></td>
</tr>
</table>