You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/store/api.md
+24-1Lines changed: 24 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
3
3
## Initial State
4
4
5
-
Configure initial state when providing Store:
5
+
Configure initial state when providing Store. `config.initialState` can be either the actual state, or a function that returns the initial state:
6
6
7
7
```ts
8
8
import { StoreModule } from'@ngrx/store';
@@ -20,6 +20,29 @@ import { reducers } from './reducers';
20
20
exportclassAppModule {}
21
21
```
22
22
23
+
### Initial State and Ahead of Time (AoT) Compilation
24
+
25
+
Angular AoT requires all symbols referenced in the construction of its types (think `@NgModule`, `@Component`, `@Injectable`, etc.) to be statically defined. For this reason, we cannot dynamically inject state at runtime with AoT unless we provide `initialState` as a function. Thus the above `NgModule` definition simply changes to:
26
+
27
+
```ts
28
+
/// Pretend this is dynamically injected at runtime
29
+
const initialStateFromSomewhere = { counter: 3 };
30
+
31
+
/// Static state
32
+
const initialState = { counter: 2 };
33
+
34
+
/// In this function dynamic state slices, if they exist, will overwrite static state at runtime.
0 commit comments