uibModal does not show items in ng-repeat

1

I'm using $uibModal to show a list of options for the user, but it's 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>
    
asked by anonymous 20.09.2016 / 02:22

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 controller itself as a reference. You need to pass the Controller that will "control" the modal in that field. In this case, pass ModalInstanceCtrl .

Examples:

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

    
21.09.2016 / 17:31