2 回答
TA贡献2003条经验 获得超2个赞
在here$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>
TA贡献1805条经验 获得超10个赞
因为您正在使用ng-if指令,它会创建新的范围,因此状态不可见。尝试使用controllerAs语法或使用ng-hide或ng-show指令。
试试这个
<div ng-controller="payCtrl as vm" ng-init="vm.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="vm.status=='success'">
// load response data in elements
</div>
<div class="row row-space" ng-if="vm.status=='progress'">
// Progress bar takes place
</div>
</form>
</div>
<div>
并且在控制器使用var vm = this;代替$scope;
var vm = this;
vm.loadResponseData = function() {
vm.post(contextRoot + getResponseData(function(data) {
var status = sessionStorage.getItem("status");
vm.status = status ;
sessionStorage.setItem('data', JSON.stringify(data));
});
};
添加回答
举报