angularjs – module.config中提供哪些提供商/服务?

前端之家收集整理的这篇文章主要介绍了angularjs – module.config中提供哪些提供商/服务?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我想使用$document从输入字段获取一个服务器值.
var base_url = $document[0].getElementById('BaseUrl').value;

基本URL用于抓取模板.

var base_url = $document[0].getElementById('BaseUrl').value;

$routeProvider.when('/alert',{
  controller: function () { },templateUrl: base_url + '/partials/instances.html'
});

由于$文件抛出一个不知道的错误,我猜测它在配置中不可用有没有办法找出什么是可用的,什么不是?我也可以使用$http从服务器获取数据,但也不可用.

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.

鉴于上述,您只能注入常量和提供者(在API文档中标记有提供者后缀).这可能会回答您的问题,但无法解决您的模板加载问题…

我想知道你是否不能简单地使用HTML中的基本标签,然后简单地使用相对路径(基础)而不指定绝对路径? Sth(只要基本配置正确):

$routeProvider.when('/alert',templateUrl: 'partials/instances.html'
});

猜你在找的Angularjs相关文章