|
1 | 1 | import { Component } from '@angular/core';
|
2 |
| -import { FormControl, FormGroup, Validators } from '@angular/forms'; |
3 |
| - |
4 |
| -import { SEErrorRefresh } from '@delon/abc/se'; |
5 |
| -import { NzMessageService } from 'ng-zorro-antd/message'; |
6 | 2 |
|
7 | 3 | @Component({
|
8 | 4 | selector: 'app-demo',
|
9 |
| - template: ` |
10 |
| - <h3>Operating</h3> |
11 |
| - <div class="mb-md"> |
12 |
| - <button nz-button (click)="resetErrors()">Reset all errors</button> |
13 |
| - </div> |
14 |
| - <form nz-form #f="ngForm" se-container [errors]="ngModelErrors" gutter="32"> |
15 |
| - <se label="App Key" [error]="{ required: '请填写', pattern: '只能包含a-z, 0-9之间' }"> |
16 |
| - <input |
17 |
| - type="text" |
18 |
| - nz-input |
19 |
| - [(ngModel)]="i.ak" |
20 |
| - name="ak" |
21 |
| - required |
22 |
| - pattern="^[a-z0-9]*$" |
23 |
| - placeholder="必填项,且只能包含a-z, 0-9之间" |
24 |
| - /> |
25 |
| - </se> |
26 |
| - <ng-template #appSecretRequired> 请填写,密钥<a (click)="msg.success('success')">生成</a>地址。 </ng-template> |
27 |
| - <se label="App Secret" [error]="{ required: appSecretRequired, pattern: '只能包含0-9之间' }"> |
28 |
| - <input |
29 |
| - type="text" |
30 |
| - nz-input |
31 |
| - [(ngModel)]="i.sk" |
32 |
| - name="sk" |
33 |
| - required |
34 |
| - maxlength="32" |
35 |
| - pattern="^[0-9]*$" |
36 |
| - placeholder="必填项,且只能包含0-9之间" |
37 |
| - /> |
38 |
| - </se> |
39 |
| - <se> |
40 |
| - <button nz-button nzType="primary" [disabled]="f.invalid">Save</button> |
41 |
| - </se> |
42 |
| - </form> |
43 |
| - <h3>Reactive</h3> |
44 |
| - <form nz-form [formGroup]="validateForm" se-container gutter="32" [errors]="reactiveErrors"> |
45 |
| - <se label="App Key" [error]="{ required: 'Please input your username!', pattern: 'Incorrect format, muse be A' }"> |
46 |
| - <input formControlName="userName" nz-input placeholder="Username" /> |
47 |
| - </se> |
48 |
| - <se label="App Secret" error="Please input your Password!"> |
49 |
| - <input formControlName="password" nz-input type="password" placeholder="Password" /> |
50 |
| - </se> |
51 |
| - <se> |
52 |
| - <button nz-button nzType="primary" [disabled]="!validateForm.valid">Log in</button> |
53 |
| - </se> |
54 |
| - </form> |
55 |
| - ` |
| 5 | + template: `` |
56 | 6 | })
|
57 | 7 | export class DemoComponent {
|
58 |
| - validateForm = new FormGroup({ |
59 |
| - userName: new FormControl<string | null>(null, [Validators.required, Validators.pattern(/A/)]), |
60 |
| - password: new FormControl(null, [Validators.required]), |
61 |
| - remember: new FormControl(true) |
62 |
| - }); |
63 |
| - |
64 |
| - i: { ak?: string; sk?: string } = {}; |
65 |
| - ngModelErrors: SEErrorRefresh[] = []; |
66 |
| - reactiveErrors: SEErrorRefresh[] = []; |
67 |
| - |
68 |
| - constructor(public msg: NzMessageService) {} |
69 |
| - |
70 |
| - resetErrors(): void { |
71 |
| - this.ngModelErrors = [{ name: 'ak', error: 'Required field, and can only contain a-z, 0-9' }]; |
72 |
| - this.reactiveErrors = [ |
73 |
| - { name: 'userName', error: 'Required username' }, |
74 |
| - { name: 'password', error: 'Required password' } |
75 |
| - ]; |
| 8 | + _n(): void { |
| 9 | + console.log('n'); |
76 | 10 | }
|
77 | 11 | }
|
0 commit comments