Skip to content

Commit 2996de1

Browse files
author
natee
committed
startup section
1 parent 3d22def commit 2996de1

File tree

2 files changed

+56
-2
lines changed

2 files changed

+56
-2
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2069,7 +2069,7 @@ While this guide explains the *what*, *why* and *how*, I find it helpful to see
20692069
### Configuration
20702070
- Inject code into [module configuration](https://docs.angularjs.org/guide/module#module-loading-dependencies) that must be configured before running the angular app. Ideal candidaes include providers and constants.
20712071
2072-
*Why?:* This makes it easier to have a less places for configuration.
2072+
*Why?*: This makes it easier to have a less places for configuration.
20732073
20742074
```javascript
20752075
angular

i18n/zh_CN.md

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
1. [应用程序结构LIFT原则](#应用程序结构LIFT原则)
3636
1. [应用程序结构](#应用程序结构)
3737
1. [模块化](#模块化)
38+
1. [启动逻辑](#启动逻辑)
3839
1. [Angular $包装服务](#angular $包装服务)
3940
1. [测试](#测试)
4041
1. [动画](#动画)
@@ -2042,7 +2043,60 @@
20422043
20432044
**[返回顶部](#目录)**
20442045
2045-
## Angular $包装的服务
2046+
## 启动逻辑
2047+
2048+
### 配置
2049+
- 必须在angular应用启动前进行配置才能把代码注入到[模块配置](https://docs.angularjs.org/guide/module#module-loading-dependencies),理想的一些case应该包括providers和constants。
2050+
2051+
*为什么?*:这使得在更少的地方进行配置变得容易。
2052+
2053+
```javascript
2054+
angular
2055+
.module('app')
2056+
.config(configure);
2057+
2058+
configure.$inject =
2059+
['routerHelperProvider', 'exceptionHandlerProvider', 'toastr'];
2060+
2061+
function configure (routerHelperProvider, exceptionHandlerProvider, toastr) {
2062+
exceptionHandlerProvider.configure(config.appErrorPrefix);
2063+
configureStateHelper();
2064+
2065+
toastr.options.timeOut = 4000;
2066+
toastr.options.positionClass = 'toast-bottom-right';
2067+
2068+
////////////////
2069+
2070+
function configureStateHelper() {
2071+
routerHelperProvider.configure({
2072+
docTitle: 'NG-Modular: '
2073+
});
2074+
}
2075+
}
2076+
```
2077+
2078+
### 运行块
2079+
2080+
- 任何在应用程序启动时需要运行的代码都应该在factory中声明,通过一个function暴露出来,然后注入到[运行块](https://docs.angularjs.org/guide/module#module-loading-dependencies)。
2081+
2082+
*为什么?*:直接在运行块处写代码将会使得测试变得很困难,相反,如果放到facotry则会使的抽象和模拟变得很简单。
2083+
2084+
```javascript
2085+
angular
2086+
.module('app')
2087+
.run(runBlock);
2088+
2089+
runBlock.$inject = ['authenticator', 'translator'];
2090+
2091+
function runBlock(authenticator, translator) {
2092+
authenticator.initialize();
2093+
translator.initialize();
2094+
}
2095+
```
2096+
2097+
**[返回顶部](#目录)**
2098+
2099+
##Angular $包装服务
20462100
20472101
###$document和$window
20482102

0 commit comments

Comments
 (0)