angularjsangular-ui-bootstrapangular-ui-modal

ui-bootstrap how to get the scope in view aliased


View calling modal

I have this code you should: open a modal bringing the data within the controller being used by the angular-ui-bootstrap. But it is not getting the result of the "item" that is selected.

in my controller:

function EntidadesCtrlFn(EntidadeService, $uibModal, $log) {
 var vm = this;
 vm.animationsEnabled = true;
 vm.modalEdit = function(size, selectedEntidade) {

  var modalInstance = $uibModal.open({
    animation: vm.animationsEnabled,
    templateUrl: './app/modulos/entidades/views/edit-entidades.html',
    controller: function($scope, $uibModalInstance, entidade) {
      vm.entidade = entidade;
    },
    controllerAs: 'vm',
    bindToController: true,
    size: size,
    resolve: {
      entidade: function() {
        return selectedEntidade;
      }
    }
  });

  modalInstance.result.then(function(selectedItem) {
    vm.selected = selectedItem;
  }, function() {
    console.log('Modal dismissed.result.');
    $log.info('Modal dismissed at: ' + new Date());
  });
};

in view of list:

<div class="row" ng-controller="EntidadesCtrl as vm">
...
<button class="btn btn-default" ng-click="vm.modalEdit('lg', entidade)" type="button">
  Editar
</button>
...

This modal opens, but does not bring the contents of:

controller: function($scope, $uibModalInstance, entidade) {
      vm.entidade = entidade;
    },

TemplateUrl:

<section ng-controller="EntidadesCtrl as vm">
 {{vm}}
 <div class="modal-header">
  <h3 class="modal-title">Editando entidade</h3>
 </div>
 <div class="modal-body">
  ...
 </div>
 <div class="modal-footer">
  <button class="btn btn-primary" ng-click="ok()" type="button">OK</button>
  <button class="btn btn-warning" ng-click="cancel()" type="button">Cancel</button>
 </div>
</section>

Solution

  • Solved. I ended up forgetting to pass "this" in the controller ;

    Sorry about that.

    In the controller modal:

    controller: function($uibModalInstance, entidade) {
      var vm = this;
      vm.entidade = entidade;
    },