Golang+Angular+MariaDB #14 User 정보 수정
Development/Go+Angular+MariaDB 2021. 2. 3. 21:23 |728x90
참고영상 : Consumindo uma (GO) API REST com Angular 7 Parte 4 # 28
더보기

Google Font 페이지

Web 결과화면
폰트 변경
Google Font (링크)

index.html 에 추가
<link rel="preconnect" href="https://fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css2?family=Montserrat" rel="stylesheet">
src/app/app.component.css 에 추가
.container {
font-family: 'Montserrat', sans-serif;
}
src/app/app.service.ts 수정
...
export class UserService {
...
constructor(private http: HttpClient) {
...
}
public getUsers() {
...
}
public getUser(id: string) {
...
}
public postUser(user: any) {
...
}
// 코드 추가
public putUser(user: any) {
let data = {
"id" : user.id,
"name" : user.name,
"email" : user.email,
"password" : user.password
};
return this.http.put(`${this.Uri}/${user.id}`, JSON.stringify(data));
}
}
src/app/app.component.ts 수정
...
export class AppComponent {
...
constructor(public service: UserService) {
...
}
public onSubmit(form: FormGroup) {
console.log(form.value)
if( form.value.id == null) {
this.service.postUser(form.value)
.subscribe((resp) => {
console.log(resp)
if(resp["Status"] == 201) {
this.clearForm(); // 코드 추가
this.service.getUsers()
.subscribe((data) => this.users = data);
}
});
} else {
// 코드 추가 : user 데이터 수정
this.service.putUser(form.value)
.subscribe((resp) => {
console.log(resp);
if(resp["Status"] == 200) {
this.clearForm();
this.updateList(form.value);
}
});
}
}
// 코드 추가 : user 데이터를 Form에 전달
public onEdit(id: string) {
this.service.getUser(id)
.subscribe((data) => {
this.service.selectedUser = data;
});
}
// 코드 추가 : 테이블 내 user 데이터 갱신
public updateList(user: any) {
for(var i = 0; i < this.users.length; i++) {
if(user.id == this.users[i].id) {
this.users[i] = user;
return;
}
}
}
// 코드 추가 : Form 비우기
public clearForm() {
this.service.selectedUser = {
"id": null,
"name": '',
"email": '',
"password": ''
};
}
}

728x90
'Development > Go+Angular+MariaDB' 카테고리의 다른 글
| Golang+Angular+MariaDB #16 Bootstrap Modal 추가 + Source 보완 (0) | 2021.02.04 |
|---|---|
| Golang+Angular+MariaDB #15 User 정보 삭제 (0) | 2021.02.04 |
| Golang+Angular+MariaDB #13 Font Awesome 아이콘 적용 (0) | 2021.02.03 |
| Golang+Angular+MariaDB #12 User 정보 등록 (0) | 2021.02.03 |
| Golang+Angular+MariaDB #11 입력을 위한 Form 세팅 (0) | 2021.02.02 |