uibModal does not show the items in ng-repeat

Asked

Viewed 103 times

1

I’m using $uibModal to display a list of options for the user, but is not appearing in the modal.

Controller

app.controller("ConsultaFiltroController", function($scope, $http, $uibModal, $log) { 

  $scope.items = ['Em Análise', 'Pendente', 'Cancelado', 'Liberado', 'Aguardando Averbação', 'Averbado'];

$scope.animationsEnabled = true;

$scope.open = function(size, contrato) {

    var modalInstance = $uibModal.open({
        animation: $scope.animationsEnabled,
        templateUrl: 'myModalContent.html',
        controller: 'ConsultaFiltroController',
        size: size,
        resolve: {
            items: function() {
                return $scope.items;

            }
        }
    });

    modalInstance.result.then(function(selectedItem) {
        $scope.selected = selectedItem;
        console.log($scope.selected)

    }, function() {
        $log.info('Modal dismissed at: ' + new Date());
    });
};

  $scope.toggleAnimation = function() {
    $scope.animationsEnabled = !$scope.animationsEnabled;
};

});

app.controller('ModalInstanceCtrl', function($scope, $uibModalInstance, items) {


$scope.items = items;
$scope.selected = {
    item: $scope.items[0]
};

$scope.ok = function() {
    $uibModalInstance.close($scope.selected.item);
};

$scope.cancel = function() {
    $uibModalInstance.dismiss('cancel');
};
});

HTML

  <script type="text/ng-template" id="myModalContent.html">
      <div class="modal-header">
          <h3 class="modal-title">Status</h3>
      </div>
      <div class="modal-body">
          <ul>
              <li ng-repeat="item in items">
                  <a href="#" ng-click="$event.preventDefault(); selected.item = item">{{ item }}</a>
              </li>
          </ul>
        Selecionado: <b>{{ selected.item }}</b>
      </div>
      <div class="modal-footer">
          <button class="btn btn-primary" type="button" ng-click="ok()">OK</button>
          <button class="btn btn-warning" type="button" ng-click="cancel()">Cancel</button>
      </div>
  </script>

1 answer

0

The error is in the section marked below:

 var modalInstance = $uibModal.open({
    animation: $scope.animationsEnabled,
    templateUrl: 'myModalContent.html',
    controller: 'ConsultaFiltroController', // Tá errado!
    size: size,
    resolve: {
        items: function() {
            return $scope.items;

        }
    }
});

You are passing yourself controller as reference. You need to pass the Controller that will "control" the modal in this field. In this case, pass ModalInstanceCtrl.

Examples:

Note: For me, it worked using Angular Ui Bootstrap 2.1, along with the Angular 1.5.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.