Resolve in uibmodal /route

643 Views Asked by At

I have this code:

var b = 1

var a = $uibModal.open({
    ariaLabelledBy: 'modal-title',
    ariaDescribedBy: 'modal-body',
    templateUrl: 'enteModal.html',
    controller: 'enteCtrl',
    resolve: {
        obj: {"id" : id, "description" : "blabla"},
        id: eval(b),
    }
});

And it works, but I dont know why. I've read the doc of resolve, that should be a map key : String or key : function.

eval(id) and {..} are an integer and an object, not a factory function, as far as I know, Resolve uses angular.injector().invoke(), but on object or integer returns error

But the controller resolves correctly obj and id. Why it works with object or integer? The doc is wrong? or uibmodal resolve is not the same resolve of route?

1

There are 1 best solutions below

3
Amit Malik On

Your resolve object needs to be a map of string: function, where string is the name of the dependency that will be injected into your modal's controller, and function is a factory function that will be used to provide that dependency when the controller is instantiated.

obj: {"id" : id, "description" : "blabla"},
id: eval(b),

In your case keys are 'obj' and 'id' and their value are {"id" : id, "description" : "blabla"} and eval(b) resp.