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

AngularJS依赖注入的值在module.config内部

发布时间:2020-12-17 08:34:45 所属栏目:安全 来源:网络整理
导读:尝试为模块设置一些帮助者的价值。尝试与服务和价值,它没有帮助: var finance = angular.module('finance',['finance.services']) .value("helpers",{ templatePath: function (name) { return '/areas/scripts/finance/templates/' + name + '/index.html
尝试为模块设置一些帮助者的价值。尝试与服务和价值,它没有帮助:
var finance = angular.module('finance',['finance.services'])
    .value("helpers",{
        templatePath: function (name) {
            return '/areas/scripts/finance/templates/' + name + '/index.html';
        }
    })
    .config(['$routeProvider','helpers',function ($routeProvider,helpers) {
    $routeProvider.
        when('/',{
            templateUrl: helpers.getTemplatePath('dashboard'),controller: DashboardController
        })            
        .when('/people',{
            templateUrl: '/areas/scripts/app/people/index.html',controller: PeopleController
        })
        .otherwise({
            redirectTo: '/dashboard'
        });
}]);

我做错了什么?

问题是,你试图注入一个值对象帮助在AngularJS模块的配置块,这是不允许的。您只能在配置块中注入常量和提供程序。

AngularJS documentation(节:“模块加载和依赖”)提供了对此的洞察:

A module is a collection of configuration and run blocks which get
applied to the application during the bootstrap process. In its
simplest form the module consist of collection of two kinds of blocks:

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.

(编辑:李大同)

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

    推荐文章
      热点阅读