Skip to content

Commit 2649d9c

Browse files
author
Lieven Van Gestel
committed
docs: ✏️ Correct implementation of WindowModule
Issues: 99
1 parent aad9bb0 commit 2649d9c

File tree

4 files changed

+17
-56
lines changed

4 files changed

+17
-56
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<h2 class="h4 u-margin-bottom">Window</h2>
22

33
<p class="u-margin-bottom">
4-
Utility to mount the global Window interface into your component using dependency injection.
4+
Utility to reference the global window object indirectly.
55
</p>
66

77
<div class="u-margin-bottom">
@@ -16,20 +16,16 @@ <h2 class="h4 u-margin-bottom">Window</h2>
1616
<aui-code-snippet [codeSnippet]="codeExampleJS2"></aui-code-snippet>
1717
</div>
1818

19-
<div class="u-margin-bottom">
20-
<aui-code-snippet [codeSnippet]="codeExampleJS3"></aui-code-snippet>
21-
</div>
22-
2319
<div class="u-margin-bottom">
2420
<aui-code-snippet [codeSnippet]="codeExampleHTML"></aui-code-snippet>
2521
</div>
2622

2723
<p class="u-margin-bottom-xs">
28-
These are the current frame's height and width:
24+
These are the window's current height and width:
2925
</p>
3026
<dl class="a-definition-list u-margin-bottom">
3127
<dt>Height:</dt>
32-
<dd><pre>{{ windowObject.innerHeight }}</pre></dd>
28+
<dd><pre>{{ window?.innerHeight }}</pre></dd>
3329
<dt>Width:</dt>
34-
<dd><pre>{{ windowObject.innerWidth }}</pre></dd>
30+
<dd><pre>{{ window?.innerWidth }}</pre></dd>
3531
</dl>

packages/utils/examples/src/utils/pages/window/window.page.ts

+7-29
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,9 @@ import { WINDOW } from '@acpaas-ui/ngx-components/utils';
33

44
@Component({
55
templateUrl: './window.page.html',
6-
// fix for `@Inject` and global interface type
7-
// https://github.com/angular/angular/issues/15640
8-
providers: [
9-
{
10-
provide: WINDOW,
11-
useValue: window,
12-
},
13-
],
146
})
157
export class UtilsWindowDemoPageComponent {
16-
public importModule = `import { WindowModule } from '@acpaas-ui/ngx-components/utils';
8+
public importModule = `import { WindowModule, WINDOW_PROVIDERS } from '@acpaas-ui/ngx-components/utils';';
179
1810
@NgModule({
1911
imports: [
@@ -26,31 +18,17 @@ export class AppModule {};`;
2618

2719
public codeExampleJS1 = `import { WINDOW } from '@acpaas-ui/ngx-components/utils';`;
2820

29-
public codeExampleJS2 = `@Component({
30-
templateUrl: './window.page.html',
31-
// fix for @Inject and global interface type
32-
// https://github.com/angular/angular/issues/15640
33-
providers: [
34-
{
35-
provide: WINDOW,
36-
useValue: window,
37-
},
38-
],
39-
})`;
40-
41-
public codeExampleJS3 = `public windowObject = this.window;
42-
constructor(
43-
@Inject(WINDOW) private window
44-
) {}`;
21+
public codeExampleJS2 = `constructor(
22+
@Inject(WINDOW) public window
23+
) {}`;
4524

4625
public codeExampleHTML = `<dl>
4726
<dt>Height:</dt>
48-
<dd><pre>{{ windowObject.innerHeight }}</pre></dd>
27+
<dd><pre>{{ window.innerHeight }}</pre></dd>
4928
<dt>Width:</dt>
50-
<dd><pre>{{ windowObject.innerWidth }}</pre></dd>
29+
<dd><pre>{{ window.innerWidth }}</pre></dd>
5130
</dl>`;
52-
public windowObject = this.window;
5331
constructor(
54-
@Inject(WINDOW) private window
32+
@Inject(WINDOW) public window
5533
) {}
5634
}

packages/utils/examples/src/utils/utils.module.ts

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
FilterModule,
77
LabelsModule,
88
WindowModule,
9+
WINDOW_PROVIDERS,
910
} from '@acpaas-ui/ngx-components/utils';
1011
import { CodeSnippetModule } from '@acpaas-ui/ngx-components/code-snippet';
1112

@@ -24,5 +25,6 @@ import { Pages } from './pages/index';
2425
declarations: [
2526
Pages,
2627
],
28+
providers: [WINDOW_PROVIDERS],
2729
})
2830
export class UtilsExamplesModule {}

packages/utils/lib/src/window/README.md

+4-19
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Visit our [documentation site](https://acpaas-ui.digipolis.be/) for full how-to
1616
### Example
1717

1818
```typescript
19-
import { WindowModule } from '@acpaas-ui/ngx-components/utils';
19+
import { WindowModule, WINDOW_PROVIDERS } from '@acpaas-ui/ngx-components/utils';
2020

2121
@NgModule({
2222
imports: [
@@ -33,32 +33,17 @@ import { WINDOW } from '@acpaas-ui/ngx-components/utils';
3333
```
3434

3535
```typescript
36-
@Component({
37-
templateUrl: './window.page.html',
38-
// fix for @Inject and global interface type
39-
// https://github.com/angular/angular/issues/15640
40-
providers: [
41-
{
42-
provide: WINDOW,
43-
useValue: window,
44-
},
45-
],
46-
})
47-
```
48-
49-
```typescript
50-
public windowObject = this.window;
5136
constructor(
52-
@Inject(WINDOW) private window
37+
@Inject(WINDOW) public window
5338
) {}
5439
```
5540

5641
```html
5742
<dl>
5843
<dt>Height:</dt>
59-
<dd><pre>{{ windowObject.innerHeight }}</pre></dd>
44+
<dd><pre>{{ window.innerHeight }}</pre></dd>
6045
<dt>Width:</dt>
61-
<dd><pre>{{ windowObject.innerWidth }}</pre></dd>
46+
<dd><pre>{{ window.innerWidth }}</pre></dd>
6247
</dl>
6348
```
6449

0 commit comments

Comments
 (0)