JavaScript Angular UI bootstrap uibModalInstance.result not yielding any value

Below is my code for the directive cabinet and my two controllers CabinetThumbnails,ModalCtrl. Based on my requirement i am using the directive cabinet and the CabinetThumbnails to render couple of widgets and then on click of every widget using ModalCtrl to open a popup. The Widgets are generating fine, pop-up is opening fine too but (uibModalInstance.result.then(function (thumbnailData)) is not working. So , its not hitting the service too cabinetService.getComments(thumbnailData). What's wrong here ?couldn't figure out.

function () {
    'use strict';

    angular
        .module('myModule')
        .directive('cabinet', function () {
            return {
                restrict: 'E',
                replace: true,
                controller: CabinetThumbnails,
                controllerAs: 'ctrl',
                bindToController: true,
                link: link,
                templateUrl: 'app/cabinet/cabinet.directive.html',
                scope: {
                    thumbnail: '='
                }
            };
        });
    function link(scope, el, attrs) {
    }

    CabinetThumbnails.$inject = ['$scope','$uibModal','cabinetService'];

    function CabinetThumbnails($scope,$uibModal,cabinetService) {
        var vm = this;

        vm.showImage = showImage;

        activate();

        function activate() {
        }

        function showImage() {
            var uibModalInstance = $uibModal.open({
                animation: true,
                templateUrl: 'app/components/capture/cabinet.pop-up.html',
                controller: ModalCtrl,
                controllerAs: 'ctrl',
                size: 'lg',
                resolve: {
                    thumbnailData: function () {
                        return vm.thumbnail;
                    }
                }
            });

            uibModalInstance.result.then(function (thumbnailData) {
                spinner.spinnerShow();

                //call the service to get the comments
                cabinetService
                    .getComments(thumbnailData)
                    .then(function (data) {
                      $scope.comments = data;
                    })
                    .catch(function (err) {
                        growl.err('Unable to open the screen shot, Please try later !', {ttl: 20000});
                    })
                    .finally(spinner.spinnerHide);
            }, function () {
                $log.info('Modal dismissed at: ' + new Date());
            });
        }
    }

    ModalCtrl.$inject = ['$scope', '$uibModalInstance', 'thumbnailData', 'growl'];

    function ModalCtrl($scope, $uibModalInstance, thumbnailData, growl) {
        var ctrl = this;

        ctrl.thumbnailData = thumbnailData;
        ctrl.cancel = cancel;

        function cancel() {
            $uibModalInstance.dismiss();
        }
    }
}());
Answer:1

Here are a couple things to consider:

  1. First of all you don't need to use controllerAs when you're defining the modal, in ui-bootstrap you should just use controller: myModalController as vm (or in your case ctrl instead).

  2. In your directive however you're defining controllerAs: 'ctrl', but you later use vm.

  3. In you modal controller you are only using the $uibModalInstance.dismiss() method, the dismiss method closes the modal and activates the promise rejection handler for the uibModalInstance.result promise. You should use $uibModalInstance.close() to activate the resolve handler. otherwise all that code wouldn't run.

I would have written it like this

   spinner.spinnerShow();

   $uibModal.open({
       animation: true,
       templateUrl: 'app/components/capture/cabinet.pop-up.html',
       controller: ModalCtrl as ctrl,
       size: 'lg',
       resolve: {
           thumbnailData: function () {
               return ctrl.thumbnail;
           }
       }
   }).result
        .then(function (thumbnailData) {
            //call the service to get the comments
            return cabinetService.getComments(thumbnailData);   
        }, function() {
             $log.info('Modal dismissed at: ' + new Date());
        }).then(function (data) {
            // we get to this 'then' after cabinetService.getComments finished
            $scope.comments = data;
        }).catch(function (err) {
            $log.err('Unable to open the screen shot, Please try later !', {ttl: 20000});
        }).finally(spinner.spinnerHide);
    }

And add

ctrl.ok = function() {
    $uibModalInstance.close(valueForResolveHandler);
};

to ModalCtrl

Answer:2

Are there any approaches when using both immutable.js and redux-form that don't require calling .toJS()? I can see the suggested approach on this issue is to call .toJS() on the Map object before ...

Are there any approaches when using both immutable.js and redux-form that don't require calling .toJS()? I can see the suggested approach on this issue is to call .toJS() on the Map object before ...

  1. redux form immutable initial values
  2. redux-form/immutable field
  3. redux form immutable js
  4. redux-form immutable change
  5. redux form immutable props
  6. redux-form/immutable typescript
  7. redux form immutable fieldarray
  8. redux-form-immutable npm
  9. react redux form immutable
  10. react-redux-form/lib/immutable
  11. redux-form immutable values

So when I execute this code, it adds a space between names[i] and the string? var names = ["Bob", "Daniel", "John", "Jimmy", "Joseph"] for (var i = 0; i < names.length; i ++) { console.log("...

So when I execute this code, it adds a space between names[i] and the string? var names = ["Bob", "Daniel", "John", "Jimmy", "Joseph"] for (var i = 0; i < names.length; i ++) { console.log("...

  1. code adding space
  2. code for adding space in html
  3. html code for adding space between lines
  4. html code for adding space between images

I have inherited legacy code that invokes a Javascript in external file for a link action. Below is a snippet of the JS function function webaction(){ $.ajax({ url:contextpath + '/docheck.html' ...

I have inherited legacy code that invokes a Javascript in external file for a link action. Below is a snippet of the JS function function webaction(){ $.ajax({ url:contextpath + '/docheck.html' ...

I have an array like this: var data = [ {label:1, quater :'Q1', y:34}, {label:2, quater:'Q1', y:20}, {label:3, quater:'Q1', y:30}, {label:1, quater:'Q2', y:77}, ...

I have an array like this: var data = [ {label:1, quater :'Q1', y:34}, {label:2, quater:'Q1', y:20}, {label:3, quater:'Q1', y:30}, {label:1, quater:'Q2', y:77}, ...

  1. percentage calculation array
  2. javascript calculate percentage array