简体   繁体   English

在uibmodal / route中解析

[英]Resolve in uibmodal /route

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 . 我已经阅读了resolve 文档 ,该文档应该是map Stringkeyfunction

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 eval(id)和{..}是整数,是一个对象,不是工厂函数,据我所知,Resolve使用angular.injector()。invoke(),但是在对象或整数上返回错误

But the controller resolves correctly obj and id . 但是控制器可以正确解析objid Why it works with object or integer? 为什么它与对象或整数一起使用? The doc is wrong? 该文档是错误的? or uibmodal resolve is not the same resolve of route? 还是uibmodal解析不是相同的路由解析?

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. 您的resolve对象必须是string:function的映射,其中string是将注入到模态控制器中的依赖项的名称,而function是工厂函数,将在实例化控制器时用于提供该依赖项。

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. 在您的情况下,键为'obj'和'id',其值分别为{“ id”:id,“ description”:“ blabla”}和eval(b)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM