我的想法是將數據從我的html發送到角度腳本中的函數,後者又調用計算某些值的節點腳本,使用其自身的函數產生結果,並以json響應的形式將值返回給角腳本。無法從角度獲取值到我的nodejs
HTML
<div ng-app="myApp" ng-controller="myController" ng-init='isFocused=true'>
<div class="col-lg-5 col-md-8 col-sm-12 col-xs-12">
<input width="100%" type="text" class="form-control" id="operand1" name="operand1" style="height:50px; font-size:32px" ng-model="operand1" ng-focus=' isFocused="operand1" ' autofocus>
</div>
<div class="col-lg-2 col-md-8 col-sm-12 col-xs-12 text-center" style="font-size:32px">
{{op}}
</div>
<div class="col-lg-5 col-md-8 col-sm-12 col-xs-12">
<input width="100%" type="text" class="form-control" style="height:50px; font-size:32px" ng-model="operand2" ng-focus=' isFocused="operand2" ' id="operand2" name="operand2" autofocus>
</div>
</div>
<div class="col-lg-5">
<div class="row">
<div class="col-lg-3 col-md-3 col-sm-12 col-xs-12 eqProps text-center"> = </div>
<div class="col-lg-9 col-md-9 col-sm-12 col-xs-12"style="font-size:32px" ng-model="output">
{{output}}
</div>
</div>
角腳本
var myApp = angular.module('myApp', []);
myApp.controller('myController', function($scope) {
$scope.operators = {
'+': add,
'-': sub,
'*': mul,
'/': div
};
$scope.op = '+';
$scope.calc = calc;
$scope.submit = function() {
$http({
method : "POST",
url : '/calculator',
data : {
"answer" : $scope.answer
}
}).success(function(data) {
$scope.output = $scope.operand1 + $scope.operand2;
}).error(function(error) {
$scope.output = 'Invalid Input';
});
};
});
/計算器映射到./routes/calculator.compute
calculator.js
exports.compute = function(req, res){
var operand1 = req.body.operand1;
var operand2 = req.body.operand2;
var operator = req.body.operator;
var json_responses;
json_responses = {"answer" : operand1+operand2};
res.send(json_responses)
};
真正的問題是,{{輸出}}不會產生輸出計算在calculator.js