[英]ng-show only working once
基本上,我正在导入文件,并且在成功/失败后显示引导面板。 我正在使用ng-show。 该面板只能工作一次。 如果我尝试第二次导入文件,则面板根本不会显示。 我认为它的关闭方式与角度无关。 如何使面板显示/隐藏多次?
这是我的控制器的一部分。
$scope.importValidatedFile = function(){
var file = $scope.importFile;
var fd = new FormData();
fd.append('file', file);
$scope.loading = true;
$http.post('rest/importfeed/import/' + $scope.selectedSource.sourceId, fd,{
transformRequest: angular.identity,
headers: {'Content-Type': undefined}
}).
success(function (data) {
$scope.loading = false;
$scope.fileSuccess = true; //here is the panel
document.getElementById('fileInput').value = "";
angular.element(document.getElementById('validate'))[0].disabled = true;
angular.element(document.getElementById('import'))[0].disabled = true;
}).
error(function (error) {
$scope.danger = true;
document.getElementById('fileInput').value = "";
angular.element(document.getElementById('validate'))[0].disabled = true;
angular.element(document.getElementById('import'))[0].disabled = true;
}).finally(function () {
$scope.loading = false;
});
};
这是html页面上的面板。
<div ng-show="fileSuccess">
<div class="row">
<div class="col-sm-9 col-lg-12">
<div class="panel-body">
<div class="col-xs-12 alert alert-success" id="success">
<button type="button" class="close" data-target="#success" data-dismiss="alert"> <span aria-hidden="true">×</span>
<span class="sr-only">Close</span>
</button>
<div class="glyphicon glyphicon glyphicon-ok success-gliph"></div>
<div class="success-text"><b>Success!</b></div>
<p class="record-text">The Record was saved.</p>
</div>
</div>
</div>
</div>
</div>
我有一个偷偷摸摸的怀疑,它是如何关闭的,以及角度如何都不知道它。
如何使ng-show中的面板多次工作?
编辑**我尝试将其添加到按钮。
<button ng-click="check();" type="button" class="close" data-target="#success" data-dismiss="alert"> <span ng-click="check();" aria-hidden="true">×</span>
<span class="sr-only">Close</span>
并且在角度控制器中
$scope.check = function (){
alert("in check");
$scope.fileSuccess = false;
};
而且仍然无法正常工作
你可以试试这个吗? 每次调用importValidateFile()时都要重置fileSucess,然后在html中将ng-show更改为ng-if。
$scope.importValidatedFile = function(){
var file = $scope.importFile;
var fd = new FormData();
fd.append('file', file);
$scope.loading = true;
$scope.fileSuccess = false;
$http.post('rest/importfeed/import/' + $scope.selectedSource.sourceId, fd,{
transformRequest: angular.identity,
headers: {'Content-Type': undefined}
}).
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.