ng g c shared/identity-input
ng g c shared/area-list
1,添加领域对象
export enum IdentityType { IdCard = 0, Insurance, Passport, Militory, Other } export interface Address { provice: string, city: string, district: string, street?: string } export interface Identity { identityNo: string; identityType: IdentityType } export interface User { id?: string; email: string; name?: string; password?: string; avatar?: string; projectIds?: string[]; taskIds?: string[]; address?: Address; dateOfBirth?: string; identity?: Identity; }
2,身份输入UI template
<div> <mat-form-field> <mat-select placeholder="证件类型" (change)="onIdTypeChange($event.value)" [(ngModel)]="identity.identityType"> <mat-option *ngFor="let type of identityTypes" [value]="type.value"> {{ type.label }} </mat-option> </mat-select> </mat-form-field> </div> <div class="id-input"> <mat-form-field class="full-width"> <input matInput type="text" placeholder="证件号码" (change)="onIdNoChange($event.target.value)" [(ngModel)]="identity.identityNo" /> <mat-error>证件号码输入有误</mat-error> </mat-form-field> </div>View Code
3, 身份类型和身份号码
private _idType = new Subject<IdentityType>(); private _idNo = new Subject<string>(); private _sub: Subscription; ngOnInit(): void { const idType$ = this.idType; const idNo$ = this.idNo; const val$ = combineLatest([idType$, idNo$]).pipe( map(([_type, _no]) => ({ identityType: _type, identityNo: _no })) ); this._sub = val$.subscribe(v => { this.identity = v; this.propagateChange(v); }); } onIdTypeChange(idType: IdentityType) { this._idType.next(idType); } onIdNoChange(idNo: string) { this._idNo.next(idNo); } private get idType(): Observable<IdentityType> { return this._idType.asObservable(); } private get idNo(): Observable<string> { return this._idNo.asObservable(); }
100
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。