gpt4 book ai didi

java - Angularjs如何仅在调用init方法后加载div内容

转载 作者:行者123 更新时间:2023-12-02 01:53:06 25 4
gpt4 key购买 nike

我是 AngularJs 的新手,最初在页面加载时即。当 loadResponseData() 正在处理时,我需要显示进度 div,在 ajax 调用完成后需要显示带有响应数据的成功 div。但成功并未显现 loadResponseData() 完成后。有没有办法在完成 ajax 调用之前显示进度条,并在收到 ajax 调用响应后显示成功 div。抱歉我的英语不好,请拯救我的日子。

<%
PayBean payBean = (PayBean) session.getAttribute("payData");
%>

<div ng-controller="payCtrl" ng-init="loadResponseData()" id="loadResponseData">

<div class="row">
<div class="col-12 col-md-12 col-sm-12 col-lg-8">
<form id="response">
<div class="row row-space" ng-if="status=='success'">
// load response data in elements
</div>
<div class="row row-space" ng-if="status=='progress'">
// Progress bar takes place
</div>
</form>
</div>
<div>

payCtrl中的方法:

$scope.loadResponseData = function() {
$http.post(contextRoot + getResponseData(function(data) {
var status = sessionStorage.getItem("status");
$scope.status = status ;
sessionStorage.setItem('data', JSON.stringify(data));
});
};

最佳答案

尝试这里的示例 $timeout 指令替换为 $http 并使用 ng-show 而不是 ng-if

var app = angular.module('app',[]);
app.controller('payCtrl',function($timeout,$scope){
$scope.status = "progress"; //by default set as progress

$scope.loadResponseData = function() {
console.log("yes called");
$timeout(function(){
$scope.status = "success";
},2000);
}
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app='app' class="container" ng-controller="payCtrl" ng-init="loadResponseData()" id="oadResponseData">

<div class="row">
<div class="col-12 col-md-12 col-sm-12 col-lg-8 center">
<form id="response" class="success">
<div class="row row-space" ng-show="status== 'success'">
<h1>success code loaded</h1>
</div>
<div class="row row-space" ng-show="status== 'progress'">
<h1>Progress code loaded</h1>
</div>
</form>
</div>
<div>

关于java - Angularjs如何仅在调用init方法后加载div内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52696063/

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