> For the complete documentation index, see [llms.txt](https://xiaoxiami.gitbook.io/angularjs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://xiaoxiami.gitbook.io/angularjs/module-li-qi-ta-fang-fa/constantvaluerunfang_fa.md).

# constant、value、run方法

## constant

* constant(name,object)
* 此方法首先运行，可以用它来声明整个应用范围内的常量，并且让它们在所有配置(config方法里)和实例(controller,service等)方法中都可用

## value

* value(name,object)
* 如果只想在服务内得到一些内容，可以通过value来申明常量

## run

* run(initializationFn)
* 想要在注入启动之后执行某些操作，⽽而这些操作需要在页面对用户可用之前执行，可以使用此方法
* 比如加载远程的模版，需要在使用前放入缓存，或者在使用操作前判断用户是否登录，未登录可以先去登陆页面

**例子：**

index.html

```markup
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">

</head>
<body>
<div ng-app="myApp">

    <div ng-controller="firstController">

    </div>



</div>


<script src="//cdn.bootcss.com/angular.js/1.4.8/angular.js"></script>
<script type="text/javascript" src="app/index.js"></script>


</body>
</html>
```

app/index.js

```javascript
angular.module('myApp',[],['$provide',function($provide){
        console.log('config');
    // $provide.factory
    // $provide.service

    // $provide.constant
    // $provide.value;

}])

.config(function(APIKEY){
    console.log(APIKEY);
        console.log('config');
})

    // 在config之后controller等其他服务之前。。
.run(function(){
    console.log('run');
})
    // 它只是可以注入任何方法
.constant('APIKEY','xxxx')

    // 只能注入controller...service factory
.value('vension','1.0.0')

.controller('firstController',['APIKEY','vension',function(APIKEY,vension){
    console.log(APIKEY);
        console.log(vension);
        console.log('controller');


}]);
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://xiaoxiami.gitbook.io/angularjs/module-li-qi-ta-fang-fa/constantvaluerunfang_fa.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
