Skip to content
This repository has been archived by the owner on May 29, 2019. It is now read-only.

Modal Resolution Not Using Locals #3405

Closed
micah-williamson opened this issue Mar 18, 2015 · 6 comments
Closed

Modal Resolution Not Using Locals #3405

micah-williamson opened this issue Mar 18, 2015 · 6 comments

Comments

@micah-williamson
Copy link

If a modal resolution contains another resolution from the same resolve block it will fail. This is not working as expected (like ui-router).

Steps to reproduce:

  • Create a Controller called MainCtrl that injects the $modal service with a scope method called openModal()
  • Create a view MainCtrl is controller. Create a button that, when clicked, calls openModal()
  • In the openModal() method use the $modal service to call $modal.open()
  • In the $modal.open call add two resolutions. The second resolution should attempt to use the first resolution.
angular.module('app', ['ui.bootstrap'])
  .controller('MainCtrl', function($scope, $modal) {

    $scope.openModal = function() {
      $modal.open({
        template: 'hello'
      });
    };

    $scope.openModal2 = function() {
      $modal.open({
        template: 'hello',
        resolve: {
          r1: function() {
            return 'hello';
          },
          // Will fail
          r2: function(r1) {
            return r1 + ' world!';
          }
        }
      });
    };

  });

JSBin: http://jsbin.com/riyijuqolu/1/edit?js,console,output

Please address.

@BobbieBarker
Copy link
Contributor

I did a look over on how our resolve block is handled in modals and compared it to how ui-router handles their resolve block. Our resolve in comparison is a very simple implementation where all the promises are pushed into an array and $q.all is used. Which is where I think the break down that this issue high lights begins. For comparison if you look at resolve.js from ui-router
https://github.com/angular-ui/ui-router/blob/master/src/resolve.js
You'll see a dramatically more complex implementation. On thate note, I don't think there is a bug here, I just don't think our modal was written to handle this use case.

@micah-williamson
Copy link
Author

@RobJacobs @rvanbaalen

I'm not opening a modal from a modal...

@micah-williamson
Copy link
Author

@BobbieBarker Do you think this should be updated? Is the expected behavior to work like ui-router resolve?

@BobbieBarker
Copy link
Contributor

Looking at the code I don't think the expected behavior is to have an implementation like ui-routers, but also looking at ui-router's implementation I can see where an enhancement could certainly be made.

@chrisirhc chrisirhc added this to the Backlog milestone Apr 13, 2015
@wesleycho
Copy link
Contributor

The UI Router implementation is quite complex compared to ours. We could copy/paste that code, but that would be duplicate code - it may end up being the best solution though. UI Router is undergoing a large refactor right now in TypeScript for the 1.0 release and potential abstraction to decouple it from Angular itself (so it can be used in Angular 2, or in any other application).

@wesleycho
Copy link
Contributor

An update on this - in order to support this, I am willing to have an interface that is pluggable as config for the modal to use and conforms to UI Router's $resolve implementation.

By default, it should use its current implementation when a provided implementation is not present.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants