加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angularjs – 如何注入依赖到module.config(configFn)在角

发布时间:2020-12-17 09:07:42 所属栏目:安全 来源:网络整理
导读:在角度,我们可以注入$ routeProvider到配置功能 module.config(function ($routeProvider) {}); 我想把我的服务注入它 module.config(function ($routeProvider,myService) {}); 我确信服务被正确定义,但它抛出一个异常说未知的myService,事件我注入 modu
在角度,我们可以注入$ routeProvider到配置功能
module.config(function ($routeProvider) {


});

我想把我的服务注入它

module.config(function ($routeProvider,myService) {


});

我确信服务被正确定义,但它抛出一个异常说未知的myService,事件我注入

module.config(function ($routeProvider,$http) {


});

它仍然说未知$ http。

你知道为什么吗?

从 Modules页,“模块加载和依赖”部分:

Configuration blocks – get executed during the provider registrations and configuration phase. Only providers and constants can be injected into configuration blocks. This is to prevent accidental instantiation of services before they have been fully configured.

Run blocks – get executed after the injector is created and are used to kickstart the application. Only instances and constants can be injected into run blocks. This is to prevent further system configuration during application run time.

所以你不能注入自己的服务,或者内置的服务像$ http到config()。改用run()。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读