我无法在HTTP post请求后分配范围变量。
控制器:
storeApp.controller("formCtrl", ['$scope', '$http', function ($scope, $http) {
$scope.variableToBeAssigned= null;
}
$scope.formsubmit = function () {
$http.post($scope.url, { "name": $scope.name}).
success(function (data, status){
$scope.variableToBeAssigned= "success";
})}
当用户提交表单时,将调用formsubmit()函数。即使在HTTP Post请求之后,“variableToBeAssigned”仍然为空。
答案 0 :(得分:-1)
您应该将该功能放在控制器内,
storeApp.controller("formCtrl", ['$scope', '$http', function ($scope, $http) {
$scope.variableToBeAssigned= null;
$scope.formsubmit = function () {
$http.post($scope.url, { "name": $scope.name}).
success(function (data, status){
$scope.variableToBeAssigned= "success";
return($scope.test1);
})}
}