Skip to content

Commit e35c6fb

Browse files
authored
docs: upgrade signal (#1889)
1 parent 634a138 commit e35c6fb

File tree

5 files changed

+167
-168
lines changed

5 files changed

+167
-168
lines changed

packages/abc/auto-focus/demo/simple.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ order: 0
1414
Simplest of usage.
1515

1616
```ts
17-
import { Component } from '@angular/core';
17+
import { Component, signal } from '@angular/core';
1818

1919
import { AutoFocusDirective } from '@delon/abc/auto-focus';
2020
import { NzButtonModule } from 'ng-zorro-antd/button';
@@ -23,8 +23,8 @@ import { NzInputModule } from 'ng-zorro-antd/input';
2323
@Component({
2424
selector: 'app-demo',
2525
template: `
26-
<button nz-button (click)="showInput = !showInput">Toggle Input</button>
27-
@if (showInput) {
26+
<button nz-button (click)="showInput.set(!showInput())">Toggle Input</button>
27+
@if (showInput()) {
2828
<div class="mt-md">
2929
<input nz-input auto-focus />
3030
</div>
@@ -33,6 +33,6 @@ import { NzInputModule } from 'ng-zorro-antd/input';
3333
imports: [NzButtonModule, NzInputModule, AutoFocusDirective]
3434
})
3535
export class DemoComponent {
36-
showInput = false;
36+
showInput = signal(false);
3737
}
3838
```

packages/abc/cell/demo/simple.md

Lines changed: 30 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Simplest of usage.
1515

1616
```ts
1717
import { JsonPipe } from '@angular/common';
18-
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, OnInit, inject } from '@angular/core';
18+
import { ChangeDetectionStrategy, Component, OnInit, inject, signal } from '@angular/core';
1919
import { FormsModule } from '@angular/forms';
2020
import { DomSanitizer } from '@angular/platform-browser';
2121
import { delay, finalize, of, take } from 'rxjs';
@@ -38,8 +38,8 @@ import { NzGridModule } from 'ng-zorro-antd/grid';
3838
<div nz-col nzSpan="8"> currency => <cell value="100000" [options]="{ unit: '$' }" /> </div>
3939
<div nz-col nzSpan="8"> cny => <cell value="100000" [options]="{ type: 'cny' }" /> </div>
4040
<div nz-col nzSpan="8">
41-
yn => <cell [value]="yn" [options]="{ type: 'boolean' }" />
42-
<a (click)="yn = !yn">Change Value</a>
41+
yn => <cell [value]="yn()" [options]="{ type: 'boolean' }" />
42+
<a (click)="yn.set(!yn())">Change Value</a>
4343
</div>
4444
<div nz-col nzSpan="8">
4545
img =>
@@ -64,16 +64,16 @@ import { NzGridModule } from 'ng-zorro-antd/grid';
6464
</div>
6565
<div nz-col nzSpan="8">
6666
link =>
67-
<cell value="Link" [options]="{ link: { url: 'https://ng-alain.com' } }" [disabled]="disabled" />
68-
<a (click)="disabled = !disabled" class="ml-sm">Change Disabled</a>
67+
<cell value="Link" [options]="{ link: { url: 'https://ng-alain.com' } }" [disabled]="disabled()" />
68+
<a (click)="disabled.set(!disabled())" class="ml-sm">Change Disabled</a>
6969
</div>
7070
<div nz-col nzSpan="8">
7171
html =>
7272
<cell [value]="HTML" [options]="{ type: 'html' }" />
7373
</div>
7474
<div nz-col nzSpan="8">
7575
SafeHtml =>
76-
<cell [value]="safeHtml" />
76+
<cell [value]="safeHtml()" />
7777
<a (click)="updateSafeHtml()" class="ml-sm">updateSafeHtml</a>
7878
</div>
7979
<div nz-col nzSpan="8">
@@ -89,20 +89,21 @@ import { NzGridModule } from 'ng-zorro-antd/grid';
8989
<cell
9090
[(value)]="checkbox"
9191
[options]="{ type: 'checkbox', tooltip: 'Tooltip', checkbox: { label: 'Label' } }"
92-
[disabled]="disabled"
92+
[disabled]="disabled()"
9393
/>
94-
{{ checkbox }}
95-
<a (click)="disabled = !disabled" class="ml-sm">Change Disabled</a>
94+
{{ checkbox() }}
95+
<a (click)="disabled.set(!disabled())" class="ml-sm">Change Disabled</a>
9696
</div>
9797
<div nz-col nzSpan="8">
9898
radio =>
9999
<cell
100100
[(value)]="radio"
101101
[options]="{ type: 'radio', tooltip: 'Tooltip', radio: { label: 'Radio' } }"
102-
[disabled]="disabled"
102+
[disabled]="disabled()"
103103
/>
104-
<a (click)="radio = !radio">Change Value</a>
105-
<a (click)="disabled = !disabled" class="ml-sm">Change Disabled</a>
104+
{{ radio() }}
105+
<a (click)="radio.set(!radio())">Change Value</a>
106+
<a (click)="disabled.set(!disabled())" class="ml-sm">Change Disabled</a>
106107
</div>
107108
<div nz-col nzSpan="8">
108109
enum =>
@@ -130,21 +131,21 @@ import { NzGridModule } from 'ng-zorro-antd/grid';
130131
</div>
131132
<div nz-col nzSpan="8">
132133
loading =>
133-
<cell value="Done" [loading]="loading" />
134-
<a (click)="loading = !loading" class="ml-md">Change</a>
134+
<cell value="Done" [loading]="loading()" />
135+
<a (click)="loading.set(!loading())" class="ml-md">Change</a>
135136
</div>
136137
<div nz-col nzSpan="8">
137138
Async =>
138-
<cell [value]="async" [loading]="asyncLoading" />
139-
@if (!asyncLoading) {
139+
<cell [value]="async" [loading]="asyncLoading()" />
140+
@if (!asyncLoading()) {
140141
<a (click)="again()" class="ml-md">Again</a>
141142
}
142143
</div>
143144
<div nz-col nzSpan="8"> Unit => <cell value="3" [options]="{ unit: '人' }" /> </div>
144145
<div nz-col nzSpan="8"> Text Unit => <cell [value]="{ text: '100', unit: '元' }" /> </div>
145146
<div nz-col nzSpan="8">
146147
custom widget =>
147-
<cell [value]="imageValue" [options]="{ widget: { key: 'test', data: 'new url' } }" />
148+
<cell [value]="imageValue()" [options]="{ widget: { key: 'test', data: 'new url' } }" />
148149
<a (click)="refreshImage()">Refresh Image</a>
149150
</div>
150151
</div>
@@ -161,29 +162,24 @@ import { NzGridModule } from 'ng-zorro-antd/grid';
161162
})
162163
export class DemoComponent implements OnInit {
163164
private readonly ds = inject(DomSanitizer);
164-
private readonly cdr = inject(ChangeDetectorRef);
165-
value: unknown = 'string';
166-
imageValue = 'https://randomuser.me/api/portraits/thumb/women/47.jpg';
167-
checkbox = false;
168-
radio = true;
169-
disabled = false;
170-
yn = true;
165+
imageValue = signal('https://randomuser.me/api/portraits/thumb/women/47.jpg');
166+
checkbox = signal(false);
167+
radio = signal(true);
168+
disabled = signal(false);
169+
yn = signal(true);
170+
loading = signal(true);
171171
default: string = '-';
172-
defaultCondition: unknown = '*';
173-
options?: CellOptions;
174172
baseList = ['string', true, false, 100, 1000000, new Date()];
175173
typeList: CellRenderType[] = ['primary', 'success', 'danger', 'warning'];
176-
now = new Date();
177174
day3 = subDays(new Date(), 3);
178175
HTML = `<strong>Strong</string>`;
179176
status: CellBadge = {
180177
WAIT: { text: 'Wait', tooltip: 'Refers to waiting for the user to ship' },
181178
FINISHED: { text: 'Done', color: 'success' }
182179
};
183-
loading = true;
184-
asyncLoading = true;
180+
asyncLoading = signal(true);
185181
async?: CellFuValue;
186-
safeHtml = this.ds.bypassSecurityTrustHtml(`<strong>Strong Html</strong>`);
182+
safeHtml = signal(this.ds.bypassSecurityTrustHtml(`<strong>Strong Html</strong>`));
187183
enum = { 1: 'Success', 2: 'Error' };
188184
enumValue = 1;
189185
bigImg: CellOptions = {
@@ -197,33 +193,22 @@ export class DemoComponent implements OnInit {
197193
this.again();
198194
}
199195

200-
refresh(): void {
201-
this.value = new Date();
202-
this.cdr.detectChanges();
203-
}
204-
205196
again(): void {
206-
this.asyncLoading = true;
197+
this.asyncLoading.set(true);
207198
this.async = (() =>
208199
of({ text: `${+new Date()}` }).pipe(
209200
take(1),
210201
delay(1000 * 1),
211-
finalize(() => {
212-
this.asyncLoading = false;
213-
this.cdr.detectChanges();
214-
})
202+
finalize(() => this.asyncLoading.set(false))
215203
)) as CellFuValue;
216-
this.cdr.detectChanges();
217204
}
218205

219206
updateSafeHtml(): void {
220-
this.safeHtml = this.ds.bypassSecurityTrustHtml(`alert('a');<script>alert('a')</script>`);
221-
this.cdr.detectChanges();
207+
this.safeHtml.set(this.ds.bypassSecurityTrustHtml(`alert('a');<script>alert('a')</script>`));
222208
}
223209

224210
refreshImage(): void {
225-
this.imageValue = `https://randomuser.me/api/portraits/thumb/women/${Math.floor(Math.random() * 50) + 10}.jpg`;
226-
this.cdr.detectChanges();
211+
this.imageValue.set(`https://randomuser.me/api/portraits/thumb/women/${Math.floor(Math.random() * 50) + 10}.jpg`);
227212
}
228213
}
229214
```

packages/abc/notice-icon/demo/basic.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { NoticeIconComponent } from '@delon/abc/notice-icon';
1212

1313
@Component({
1414
selector: 'app-demo',
15-
template: ` <notice-icon count="5" /> `,
15+
template: `<notice-icon count="5" />`,
1616
imports: [NoticeIconComponent]
1717
})
1818
export class DemoComponent {}

0 commit comments

Comments
 (0)