gpt4 book ai didi

javascript - 如何实现AngularJS异步?

转载 作者:太空宇宙 更新时间:2023-11-04 15:37:48 26 4
gpt4 key购买 nike

我正在使用 AngularJS v1.5.8,我的要求是当我单击“下一步”按钮时,它会在完成操作之前将按钮内的“正在处理...”显示为文本,我已将 $q 包含在我的服务中以获取异步设施,但不工作。请看我下面的代码。

服务

mainApp.factory('PINVerificationServices', ['$http', '$rootScope','$q', function ($http, $rootScope) {
return {
IsPermitted: function (param) {
return $q($http({
url: '/Api/ApiPINVerification/IsPermitted/' + param,
method: 'POST',
async: true
}));
}
};
}]);

Controller

mainApp.controller('PINVerificationController', function ($scope, $rootScope, $state, $window,$q, PINVerificationServices) {
$scope.SubmitText = "Next";

$scope.Next = function () {
$scope.SubmitText = "Processing...";
PINVerificationServices.IsPermitted($scope.PIN).then(function (result) {
$scope.SubmitText = "Next";
});
}
}

HTML

  <div class="list-group list-group-sm">
<div class="list-group-item">
<input class="form-control" ng-model="PIN" placeholder="PIN" required id="PIN" name="PIN" type="text" />
</div>
</div>
<button type="submit" ng-click="Next()">{{SubmitText}}</button>

最佳答案

试试这个:

 return $http({
method: 'POST',
url: '/Api/ApiPINVerification/IsPermitted/' + param
});

关于javascript - 如何实现AngularJS异步?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44157524/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com