@@ -15,7 +15,7 @@ Simplest of usage.
15
15
16
16
``` ts
17
17
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' ;
19
19
import { FormsModule } from ' @angular/forms' ;
20
20
import { DomSanitizer } from ' @angular/platform-browser' ;
21
21
import { delay , finalize , of , take } from ' rxjs' ;
@@ -38,8 +38,8 @@ import { NzGridModule } from 'ng-zorro-antd/grid';
38
38
<div nz-col nzSpan="8"> currency => <cell value="100000" [options]="{ unit: '$' }" /> </div>
39
39
<div nz-col nzSpan="8"> cny => <cell value="100000" [options]="{ type: 'cny' }" /> </div>
40
40
<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>
43
43
</div>
44
44
<div nz-col nzSpan="8">
45
45
img =>
@@ -64,16 +64,16 @@ import { NzGridModule } from 'ng-zorro-antd/grid';
64
64
</div>
65
65
<div nz-col nzSpan="8">
66
66
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>
69
69
</div>
70
70
<div nz-col nzSpan="8">
71
71
html =>
72
72
<cell [value]="HTML" [options]="{ type: 'html' }" />
73
73
</div>
74
74
<div nz-col nzSpan="8">
75
75
SafeHtml =>
76
- <cell [value]="safeHtml" />
76
+ <cell [value]="safeHtml() " />
77
77
<a (click)="updateSafeHtml()" class="ml-sm">updateSafeHtml</a>
78
78
</div>
79
79
<div nz-col nzSpan="8">
@@ -89,20 +89,21 @@ import { NzGridModule } from 'ng-zorro-antd/grid';
89
89
<cell
90
90
[(value)]="checkbox"
91
91
[options]="{ type: 'checkbox', tooltip: 'Tooltip', checkbox: { label: 'Label' } }"
92
- [disabled]="disabled"
92
+ [disabled]="disabled() "
93
93
/>
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>
96
96
</div>
97
97
<div nz-col nzSpan="8">
98
98
radio =>
99
99
<cell
100
100
[(value)]="radio"
101
101
[options]="{ type: 'radio', tooltip: 'Tooltip', radio: { label: 'Radio' } }"
102
- [disabled]="disabled"
102
+ [disabled]="disabled() "
103
103
/>
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>
106
107
</div>
107
108
<div nz-col nzSpan="8">
108
109
enum =>
@@ -130,21 +131,21 @@ import { NzGridModule } from 'ng-zorro-antd/grid';
130
131
</div>
131
132
<div nz-col nzSpan="8">
132
133
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>
135
136
</div>
136
137
<div nz-col nzSpan="8">
137
138
Async =>
138
- <cell [value]="async" [loading]="asyncLoading" />
139
- @if (!asyncLoading) {
139
+ <cell [value]="async" [loading]="asyncLoading() " />
140
+ @if (!asyncLoading() ) {
140
141
<a (click)="again()" class="ml-md">Again</a>
141
142
}
142
143
</div>
143
144
<div nz-col nzSpan="8"> Unit => <cell value="3" [options]="{ unit: '人' }" /> </div>
144
145
<div nz-col nzSpan="8"> Text Unit => <cell [value]="{ text: '100', unit: '元' }" /> </div>
145
146
<div nz-col nzSpan="8">
146
147
custom widget =>
147
- <cell [value]="imageValue" [options]="{ widget: { key: 'test', data: 'new url' } }" />
148
+ <cell [value]="imageValue() " [options]="{ widget: { key: 'test', data: 'new url' } }" />
148
149
<a (click)="refreshImage()">Refresh Image</a>
149
150
</div>
150
151
</div>
@@ -161,29 +162,24 @@ import { NzGridModule } from 'ng-zorro-antd/grid';
161
162
})
162
163
export class DemoComponent implements OnInit {
163
164
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 );
171
171
default: string = ' -' ;
172
- defaultCondition: unknown = ' *' ;
173
- options? : CellOptions ;
174
172
baseList = [' string' , true , false , 100 , 1000000 , new Date ()];
175
173
typeList: CellRenderType [] = [' primary' , ' success' , ' danger' , ' warning' ];
176
- now = new Date ();
177
174
day3 = subDays (new Date (), 3 );
178
175
HTML = ` <strong>Strong</string> ` ;
179
176
status: CellBadge = {
180
177
WAIT: { text: ' Wait' , tooltip: ' Refers to waiting for the user to ship' },
181
178
FINISHED: { text: ' Done' , color: ' success' }
182
179
};
183
- loading = true ;
184
- asyncLoading = true ;
180
+ asyncLoading = signal (true );
185
181
async? : CellFuValue ;
186
- safeHtml = this .ds .bypassSecurityTrustHtml (` <strong>Strong Html</strong> ` );
182
+ safeHtml = signal ( this .ds .bypassSecurityTrustHtml (` <strong>Strong Html</strong> ` ) );
187
183
enum = { 1 : ' Success' , 2 : ' Error' };
188
184
enumValue = 1 ;
189
185
bigImg: CellOptions = {
@@ -197,33 +193,22 @@ export class DemoComponent implements OnInit {
197
193
this .again ();
198
194
}
199
195
200
- refresh(): void {
201
- this .value = new Date ();
202
- this .cdr .detectChanges ();
203
- }
204
-
205
196
again(): void {
206
- this .asyncLoading = true ;
197
+ this .asyncLoading . set ( true ) ;
207
198
this .async = (() =>
208
199
of ({ text: ` ${+ new Date ()} ` }).pipe (
209
200
take (1 ),
210
201
delay (1000 * 1 ),
211
- finalize (() => {
212
- this .asyncLoading = false ;
213
- this .cdr .detectChanges ();
214
- })
202
+ finalize (() => this .asyncLoading .set (false ))
215
203
)) as CellFuValue ;
216
- this .cdr .detectChanges ();
217
204
}
218
205
219
206
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> ` ));
222
208
}
223
209
224
210
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 ` );
227
212
}
228
213
}
229
214
```
0 commit comments