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
Brings in one content-only commit that landed on develop:
- d4195b5 HF-238 - Review "Integration with Angular" guide and demo (#1691)
It touches `docs/guide/integration-with-angular.md`, which this PR
migrated to `docs/src/content/docs/guide/integration-with-angular.md`.
Git's rename detection auto-applied the develop-side edits to the new
location — no conflicts.
Pushes the merge so GitHub's `mergeable: CONFLICTING` flag recomputes.
Copy file name to clipboardExpand all lines: docs/src/content/docs/guide/integration-with-angular.md
+126-4Lines changed: 126 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,9 +7,111 @@ The HyperFormula API is identical in an Angular app and in plain JavaScript. Thi
7
7
8
8
Install with `npm install hyperformula`. For other options, see the [client-side installation](/docs/guide/client-side-installation) section.
9
9
10
-
## Basic usage
10
+
## Basic usage (modern Angular)
11
11
12
-
Wrap the engine in an `@Injectable` service backed by a `BehaviorSubject`. Components subscribe to the observable with the `async` pipe, which handles subscription cleanup automatically.
12
+
For modern Angular (v20+) we recommend a service that exposes a **signal**, **standalone** components, the new control flow (`@if` / `@for`) and **zoneless** change detection. Wrap the engine in an `@Injectable` service and expose its values as a read-only signal; the template reads the signal directly and Angular refreshes the view whenever it changes.
13
+
14
+
```typescript
15
+
// spreadsheet.service.ts
16
+
import { Injectable, signal } from'@angular/core';
> Signals require Angular 16+, the new control flow Angular 17+, and `provideZonelessChangeDetection` Angular 20+. For earlier versions, use the `BehaviorSubject` approach below.
110
+
111
+
112
+
## Basic usage (older Angular versions)
113
+
114
+
For broader compatibility — including Angular versions without signals or zoneless change detection — wrap the engine in an `@Injectable` service backed by a `BehaviorSubject`. Components subscribe to the observable with the `async` pipe, which handles subscription cleanup automatically.
13
115
14
116
```typescript
15
117
// spreadsheet.service.ts
@@ -27,7 +129,7 @@ export class SpreadsheetService {
27
129
constructor() {
28
130
this.hf=HyperFormula.buildFromArray(
29
131
[
30
-
[1, 2, '=A1+B1'],
132
+
[1, 4, '=A1+B1'],
31
133
// your data rows go here
32
134
],
33
135
{
@@ -48,17 +150,20 @@ export class SpreadsheetService {
48
150
}
49
151
```
50
152
51
-
Consume the service from a component and bind `values$ | async` in the template. Declare the component in your `AppModule` alongside`CommonModule`:
153
+
Consume the service from a component and bind `values$ | async` in the template. The component below is **standalone** (the default since Angular 17) and imports `CommonModule` directly, so it works without an `NgModule`. The structural directives `*ngIf` / `*ngFor` and the `async` pipe all come from`CommonModule`:
@@ -91,10 +196,27 @@ export class SpreadsheetComponent {
91
196
</ng-container>
92
197
```
93
198
199
+
### `NgModule`-based apps (Angular 13 and older)
200
+
201
+
Standalone components require Angular 14 or newer. If your project still uses `NgModule`s (or targets Angular 13 or older), drop the `standalone: true` and `imports` fields from the component above, then declare it in your module and import `CommonModule` there instead:
202
+
203
+
```typescript
204
+
// app.module.ts
205
+
@NgModule({
206
+
declarations: [SpreadsheetComponent],
207
+
imports: [BrowserModule, CommonModule],
208
+
})
209
+
exportclassAppModule {}
210
+
```
211
+
212
+
The service and template above are unchanged — only the way the component is wired up differs.
213
+
94
214
## Notes
95
215
96
216
### Provider scope
97
217
218
+
The notes below apply to both the modern and older approaches — provider scope and cleanup depend on how the service is registered, not on whether it exposes a signal or a `BehaviorSubject`.
219
+
98
220
`providedIn: 'root'` makes the service an application-wide singleton — suitable when a single HyperFormula instance is shared across the app. For per-feature or per-component instances (for example, several independent reports on one screen), provide the service at the component level via `providers: [SpreadsheetService]`; the service is then created and destroyed alongside the component.
0 commit comments