javascript - ng-show 只工作一次

标签 javascript html angularjs

基本上,我正在导入一个文件,并在成功/失败时显示引导面板。我正在使用 ng-show。该面板只能工作一次。如果我尝试第二次导入文件,面板将根本不会显示。我认为它的关闭方式与 Angular 无关。如何让面板显示/隐藏多次?

这是我的 Controller 的一部分。

$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">&times;</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>

我有一个偷偷摸摸的怀疑它是如何关闭的以及 Angular 如何不知道它。

我该怎么做才能让 ng-show 中的面板多次工作?

编辑** 我尝试将其添加到按钮中。

<button ng-click="check();" type="button" class="close" data-target="#success" data-dismiss="alert"> <span ng-click="check();" aria-hidden="true">&times;</span>
                                        <span class="sr-only">Close</span>

和 Angular Controller

 $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}
}).

关于javascript - ng-show 只工作一次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47341981/

相关文章:

javascript - 如何在表单输入框中设置文本限制

javascript - Ionic Cordova macdonst SpeechRecognition 无法启动?

javascript - 扩展模态窗口

javascript - 数组与 Postgres 中的数组重叠

javascript - 如何使用 VeeValidate (Vue.Js) 上的字典为 ValidationProvider 自定义 “required” 错误消息

javascript - 设置弹出窗口坐标

javascript - 动态创建的元素上的事件绑定(bind)?

javascript - 如何将样式添加到单击另一个按钮时创建的按钮?

javascript - 随机div,只显示其中的一部分

javascript - jQuery index() - 多级 <ul>