Golang+Angular+MariaDB #15 User 정보 삭제
Development/Go+Angular+MariaDB 2021. 2. 4. 20:27 |728x90
참고영상 : Consumindo uma (GO) API REST com Angular 7 Parte 5 # 29
더보기

Web 결과화면
src/app/app.module.ts 수정
버튼에 대한 아이콘 추가를 위해 아이콘 Module Import를 진행합니다.
...
// 코드 추가 : icon
import { faUserMinus } from '@fortawesome/free-solid-svg-icons';
import { faUserPlus } from '@fortawesome/free-solid-svg-icons';
import { faUndo } from '@fortawesome/free-solid-svg-icons';
@NgModule({
declarations: [
AppComponent
],
imports: [
...
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule {
constructor(library: FaIconLibrary) {
// 코드 수정
library.addIcons(faEdit, faUserMinus, faUserPlus, faUndo);
}
}
src/app/user.service.ts 수정
...
export class UserService {
...
constructor(private http: HttpClient) {
...
}
public getUsers() {
...
}
public getUser(id: string) {
...
}
public postUser(user: any) {
...
}
public putUser(user: any) {
...
}
// 코드 추가
public deleteUser(id: string) {
return this.http.delete(`${this.Uri}/${id}`);
}
}
src/app/app.component.ts 수정
...
export class AppComponent {
...
constructor(public service: UserService) {
...
}
public onSubmit(form: FormGroup) {
...
}
public onEdit(id: string) {
...
}
public updateList(user: any) {
...
}
// 코드 추가 : user 정보 삭제
public onDelete(id: string) {
this.service.deleteUser(id)
.subscribe((resp) => {
console.log(resp);
if(resp["Status"] == 200) {
this.users = this.users.filter((user) => user.id != id);
}
});
}
public clearForm() {
...
}
src/app/app.component.html 수정
<div class="container">
<header>
...
</header>
<hr>
<div class="row">
<div class="col-md-12">
<h3>Insert User Data</h3>
<form method="post" #form="ngForm" (ngSubmit)="onSubmit(form)">
...
<div class="form-row">
<div class="d-grid gap-2 d-md-flex justify-content-md-end">
<!-- 코드 수정 : icon 추가 -->
<button class="btn btn-sm btn-block btn-primary col-lg-2" [disabled]="!form.valid" >
submit <fa-icon icon="user-plus"></fa-icon>
</button>
<!-- 코드 수정 : icon 추가 -->
<button class="btn btn-sm btn-block btn-secondary col-lg-2" (click)="clearForm()">
clear <fa-icon icon="undo"></fa-icon>
</button>
</div>
</div>
</form>
</div>
</div>
<br>
<div class="row">
<div clas="col-md-12" *ngIf="users">
<h3>User Data List</h3>
<table class="table table-bordered table-hover text-center">
<thead>
<tr>
<th>Id</th>
<th>Name</th>
<th>Email</th>
<th>Password</th>
<th>Edit</th>
<!-- 코드 수정 -->
<th>Delete</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let user of users">
<td>{{ user.id }}</td>
<td>{{ user.name }}</td>
<td>{{ user.email }}</td>
<td>{{ user.password }}</td>
<td>
<button type="button" class="btn btn-sm btn-info col-block col-lg-8" (click)="onEdit(user.id)">
<fa-icon icon="edit"></fa-icon>
</button>
</td>
<!-- 코드 수정 : delete 추가 -->
<td>
<button type="button" class="btn btn-sm btn-danger col-block col-lg-8" (click)="onDelete(user.id)">
<fa-icon icon="user-minus"></fa-icon>
</button>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<br>
<footer>
<p class="alert text-center"></p>
</footer>
</div>

728x90
'Development > Go+Angular+MariaDB' 카테고리의 다른 글
Golang+Angular+MariaDB #17 Toast 띄우기 (0) | 2021.02.04 |
---|---|
Golang+Angular+MariaDB #16 Bootstrap Modal 추가 + Source 보완 (0) | 2021.02.04 |
Golang+Angular+MariaDB #14 User 정보 수정 (0) | 2021.02.03 |
Golang+Angular+MariaDB #13 Font Awesome 아이콘 적용 (0) | 2021.02.03 |
Golang+Angular+MariaDB #12 User 정보 등록 (0) | 2021.02.03 |