我正在学习 angularJS。我尝试过使用 angularJS 的计算器。两个组合框有输入,另一个组合框有操作。当用户单击按钮时,它必须根据用户选择的操作显示结果。但我无法找到为什么它没有显示任何输出。请你帮助我好吗
(function(angular) {
'use strict';
angular.module('calculate', [])
.controller('CalculateController', function() {
this.input1 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
this.input2 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
this.selectedInput1 = 0;
this.selectedInput2 = 0;
this.selectedOpr = '=';
this.operations = ['*', '/', '+', '-'];
this.calculate = function calculateValues(value1, value2, opr) {
alert('coming inside calculate function..');
if (opr == '+') {
return (value1 + value2);
} else if (opr == '-') {
return (value1 - value2);
} else if (opr == '*') {
return (value1 * value2);
} else if (opr == '/') {
return (value1 / value2);
}
};
this.output = function show() {
alert('Calling function..');
alert('Output is :' + this.calculateValues(this.selectedInput1, this.selectedInput2, this.selectedOpr));
};
});
})(window.angular);
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Example - example-guide-concepts-2-production</title>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.0-beta.1/angular.min.js"></script>
<script src="invoice1.js"></script>
</head>
<body >
<div ng-app="calculate" ng-controller="CalculateController as calc">
<b>Invoice:</b>
<div>
Input 1:
<select ng-model="calc.selectedInput1">
<option ng-repeat="c in calc.input1">{{c}}</option>
</select>
</div>
<div>
Input 2:
<select ng-model="calc.selectedInput2">
<option ng-repeat="d in calc.input2">{{d}}</option>
</select>
</div>
<div>
Operation:
<select ng-model="calc.selectedOpr">
<option ng-repeat="e in calc.operations">{{e}}</option>
</select>
</div>
<div>
<button class="btn" ng-click="calc.show()">Pay</button>
<br>
</div>
</div>
</body>
</html>
谢谢马尼文南