【发布时间】:2019-09-25 20:23:10
【问题描述】:
我想提交我的表单并有一个方法来使用我新创建的用户更新我的表。
从今天早上开始我就被困住了。
我已经有一个删除方法,但是错过了创建方法
这是我的html
<div class="manage-content">
<div class="title">
<mat-icon class="user-icon">how_to_reg</mat-icon>
<h3>Create a user</h3>
</div>
<form [formGroup]="form" (ngSubmit)="onSubmit()">
Value : {{form.value | json}}
<div class="form">
<div class="leftSide">
<mat-form-field class="full-width-input" appearance="outline">
<input id="firstName" matInput placeholder="First name" formControlName="f_name" #f_name>
<mat-error *ngIf="isFieldInvalid('f_name')">
The first name you've entered is malformed.
</mat-error>
</mat-form-field>
<mat-form-field class="full-width-input" appearance="outline">
<input id="middleName" matInput placeholder="Middle name" formControlName="m_name" #m_name>
<mat-error *ngIf="isFieldInvalid('m_name')">
The middle name you've entered is malformed.
</mat-error>
</mat-form-field>
<mat-form-field class="full-width-input" appearance="outline">
<input id="lastName" matInput placeholder="Last name" formControlName="l_name" #l_name>
<mat-error *ngIf="isFieldInvalid('l_name')">
The last name you've entered is malformed.
</mat-error>
</mat-form-field>
<mat-form-field class="full-width-input" appearance="outline">
<input id="email" matInput placeholder="Email" formControlName="email" #email>
<mat-error *ngIf="isFieldInvalid('email')">
The email you've entered is malformed.
</mat-error>
</mat-form-field>
<mat-form-field class="full-width-input" appearance="outline">
<div class="visibility">
<input id="password" matInput type="password" placeholder="Password" formControlName="password">
<mat-icon class="eye" *ngIf="isPasswordVisible" (click)=showPassword()>visibility</mat-icon>
<mat-icon class="eyeClosed" *ngIf="!isPasswordVisible" (click)="showPassword()">visibility_off</mat-icon>
</div>
<mat-error *ngIf="isFieldInvalid('password')">
The password you've entered is malformed.
</mat-error>
</mat-form-field>
</div>
<div class="cta-btn">
<button mat-raised-button class="createUserBtn" color="primary" type="submit" (click)="onSubmit()">Create user</button>
<button mat-raised-button class="createUserBtn" color="warn" type="submit" (click)="click()">Cancel</button>
</div>
</form>
</div>
这是我的 TS 文件 这只是我方法的一部分(正在进行中)
onSubmit() {
if (this.form.valid) {
//TODO implement method to post data to API
this.dialogRef.close(this.form.value);
this.formSubmitAttempt = true;
const Toast = Swal.mixin({
toast: true,
position: 'top-end',
showConfirmButton: false,
timer: 3000
})
Toast.fire({
type: 'success',
title: 'User created'
})
}
非常感谢您的帮助
【问题讨论】:
标签: javascript angular angular-material