angularJS阻止ng-file-upload

时间:2016-01-25 23:37:40

标签: javascript jquery angularjs ng-file-upload

我读过诸如

之类的问题

我还读了一些其他相关的问题。我是angularJS的新手,非常习惯于jQuery。我在另一个用例中触发了一个单击按钮事件并且运行得很好,但是在这个使用相同指令的用例中不起作用。

这是我的JS

'use strict';

angular.module('waspPortalApp')
  .controller('UploadNotaFiscalCtrl', ['$scope', '$timeout', 'Session', 'RequisicaoService', 'AlertService', 
    function($scope, $timeout, Session, RequisicaoService, alertService) {

      var objetoPedido = {};

      $scope.idCia = Session.get().ciaUsuarioPK.idCia;

      $scope.uploadDeNotaFiscal = function() {
          var idPedido = parseInt($('#campoPedidoUploadNota').val());
          if (!$.isNumeric(idPedido) || idPedido < 1) {
              alertService.error('N&uacute;mero do pedido inv&aacute;lido', 'Por favor, informe o n&uacute;mero do pedido ou informe um n&uacute;mero de pedido v&aacute;lido.');
              return;
          }

          alertService.informativo('Recuperando informa&ccedil;&otilde;es do pedido', 'Por favor, aguarde enquanto recuperamos informa&ccedil;&otilde;es do pedido selecionado.');
          RequisicaoService.getRequisicaoPo({
              idCia: $scope.idCia,
              listaPedidos: idPedido,
              dataEmissaoPedidoDe: '',
              dataEmissaoPedidoAte: '',
              listaCnpj: ''
          },
          function (dados) {
              objetoPedido = JSON.parse(angular.toJson(dados))[0];
              if (objetoPedido.gnre) {
                  $('#modalInserirGNRE').modal('show');
              } else {
                  $('.botao-upload-nota-fiscal')[0].click();
              }
          },
          function (httpResponse) {
          });
        };

        $scope.upfiles = [{}];


      $scope.$watch('upfiles', function () {
          var file = $scope.upfiles[0];
          if (file.name === undefined) {
              return;
          }

          var valorGNRE = $('#campoGNRE').val() ? $('#campoGNRE').val().replace(/[^\d,]+/g, '').replace(',', '.') : '0.00';
          $('#campoGNRE').val('');

          $scope.upObj = RequisicaoService.uploadNotaFiscal($scope.idCia, $('#campoPedidoUploadNota').val(), file, valorGNRE)
                    .success(function (data, status, headers, config) {

            }
            ).error(function (data, status, headers, config) {

            });
      });
    }
  ]);

HTML

<div class="panel panel-default" ng-controller="UploadNotaFiscalCtrl">
    <div style='position:inherit; margin-top:10px;'>
        <br>

        <div style='float:left;'>
            <label class="col-sm-4 control-label" title="Digite o n&uacute;mero do pedido" style='width: 75px; padding-top: 4px;' for="campoPedidoUploadNota">
                Pedido:
            </label>

            <input id="campoPedidoUploadNota" style="margin-left:10px; width:120px; height: 30px;" class="form-control" title="Digite o n&uacute;mero de Pedido" type="text">
        </div>
     </div>

     <div class="panel-footer text-right" style="margin-top: 50px;">
       <button type="button" class="btn btn-default" title="Upload de NF" ng-click="uploadDeNotaFiscal()"><i class="fa fa-upload">&nbsp;</i>Upload de NF</button>
     </div>
</div>

<div class="modal fade" id="modalInserirGNRE" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog" ng-class="{'modal-sm': size == 'sm', 'modal-sm': size == 'sm'}">
        <div class="modal-content">
            <div class="modal-header panel-footer">
                <h3 class="panel-title">Informe o valor de GNRE:</h3>
            </div>
            <div class="form-group" style="height: 70px; max-height: 70px;">
              <label class="col-sm-12 control-label" style="margin-bottom: 10px; margin-top: 10px">
                  <div style="float: left; padding-bottom: 15px; padding-left: 1px; padding-right: 15px; padding-top: 15px;" class="modal-body">
                      <input id="campoGNRE" style="margin-left:1px; width:250px; height: 30px;" class="form-control" type="text" placeholder="Valor GNRE">
                  </div>
                  <div style='float:right;' class="modal-body text-right">
                      <button type="button" class="btn btn-default botao-upload-nota-fiscal" style="margin-left: 10px; padding-top: 4px; height: 30px; color: #FFFFFF; background-color: #5CB85C;" ng-file-select="upfiles" ng-model="upfiles" ng-multiple="false">Selecionar Nota Fiscal</button>
                  </div>
              </label>
            </div>
            <div class="modal-footer panel-footer"></div>
        </div>
    </div>
</div>

我尝试过使用$ timeout,因为在其中一个相关问题的答案之一中提出但是仍然没有运气。我曾尝试在其中一个答案中写出一个指令,但仍然没有成功。

关于什么是错的任何想法?

修改

如果我将$('.botao-upload-nota-fiscal').click()移到ajax请求之外,则会点击该按钮。问题现在变成了我实际上没有加载对象,也无法进行验证,例如在成功处理程序中完成的验证。

0 个答案:

没有答案