我正在开发一个应用程序如下
function attendeeCtrl($scope, $http) {
$scope.submit = function () {
console.log($scope.noattendees);
$http({
method: 'POST',
url: 'http://localhost:2000/data',
data: {
event: $scope.event,
date: $scope.date,
spentby: $scope.spentby,
amountspent: $scope.amountspent
},
});
};
}
<div ng-app>
<h2>Team share</h2>
<div ng-controller="attendeeCtrl">
<label for="amountspent">Amount spent(Rs)</label>
<input type="text" name="amountspent" id="amountspent" ng-model="amountspent" />
<br>
<label for="noattendees">Number of attendees</label> <span name="noattendees" id="noattendees" ng-model="noattendees">{{remaining()}}</span>
</br>
<label for="amountshared">Amount Shared</label><span ng-model="amountshared" name="amountshared" id="amountshared">{{amountspent/(remaining()+1)}}</span>
</br>
<input type="submit" id="submit" value="Submit" ng-click="submit()" />
<input type="reset" id="reset" value="Reset" />
</div>
</div>
但console.log($scope.noattendees)
返回“未定义”
如何在submit方法中获取{{return()}}
的值?
请建议
答案 0 :(得分:0)
从服务器获取返回值:
$http({method: 'GET', url: '/someUrl'}).
success(function(data, status, headers, config) {
// this callback will be called asynchronously
// when the response is available
}).
error(function(data, status, headers, config) {
// called asynchronously if an error occurs
// or server returns response with an error status.
});