有没有办法为Angular $注入器提供非Angular注入目标,以便像$ http,$ scope,$ location或$ q这样的Angular结构可以注入到它中?使用Angular注入非角对象
//non-angular injection container
var injectionTarget= {
$http:undefined,
$scope:undefined
}
//means to inject into target - this is the part in question
var injector = angular.injector();
injector.injectInto(injectionTarget, ["$http", "$scope"]);
我最难找到关于如何完成我认为是非常抢手的功能的任何信息。
您是否发现https://docs.angularjs.org/api/auto/service/$injector? –
我确实看过文档,但它很神秘,当尝试使用内联示例时,它一直在抛出关于找到某个关联的injectAsset +“Provider”的错误。 – jusopi