Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite5924c2

Browse files
committed
delete employee
1 parent319b37e commite5924c2

File tree

3 files changed

+37
-24
lines changed

3 files changed

+37
-24
lines changed

‎src/app/emp/list-employee/list-employee.component.ts‎

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,26 @@ export class ListEmployeeComponent implements OnInit {
1212
constructor(privateds:EmployeeDataService){}
1313

1414
ngOnInit(){
15-
this.ds.getEmployees().subscribe(
16-
(listEmployes)=>this.employees=listEmployes,
17-
(err)=>console.log(err)
18-
);
15+
this.refreshTable();
1916
}
2017
btnClick_Edit(id:number){
2118

2219
}
2320
btnClick_Del(id:number){
2421
this.ds.deleteEmployee(id).subscribe(
2522
null,
26-
(err)=>console.log(err)
23+
(err)=>console.log(err),
24+
()=>{
25+
this.refreshTable();
26+
alert("Deleted id: "+id);
27+
}
2728
);
2829
}
30+
refreshTable(){
31+
this.ds.getEmployees().subscribe(
32+
(listEmployes)=>this.employees=listEmployes,
33+
(err)=>console.log(err)
34+
);
35+
}
2936

3037
}

‎src/app/emp/put-employee/put-employee.component.ts‎

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ export class PutEmployeeComponent implements OnInit {
2626
'emailDomain':"Email domain must be from email.com",
2727
'required':"email is required"
2828
},
29-
phone:{
30-
minLength:"must be 5 characters at least",
29+
phone:{
30+
minLength:"must be 5 characters at least",
3131
maxLength:"not more than 20 charecters"
3232
},
3333
skillName:{
@@ -44,7 +44,7 @@ export class PutEmployeeComponent implements OnInit {
4444
formErr={
4545
'fullName':'',
4646
'email':'',
47-
'phone':''
47+
'phone':''
4848
// 'skills': [{
4949
// 'skillName': '',
5050
// 'expInYear': '',
@@ -58,7 +58,7 @@ export class PutEmployeeComponent implements OnInit {
5858
this.employeeForm=newFormGroup({
5959
fullName:newFormControl('',
6060
[Validators.required,Validators.maxLength(25),Validators.minLength(2)]),
61-
phone:newFormControl('',[Validators.minLength(5),Validators.maxLength(20)]),
61+
phone:newFormControl('',[Validators.minLength(5),Validators.maxLength(20)]),
6262
email:newFormControl('',[Validators.required,CustomValidator.email,CustomValidator.emailDomain('email.com')]),
6363
skills:this.fb.array([
6464
this.addSkill()
@@ -76,12 +76,12 @@ export class PutEmployeeComponent implements OnInit {
7676
}
7777
loadEmployee(emp:IEmployee){
7878
this.employee=emp;
79-
this.employeeForm.setControl('skills',this.loadSkills(this.employee.skills));
79+
this.employeeForm.setControl('skills',this.loadSkills(this.employee.skills));
8080
this.employeeForm.patchValue(this.employee);
8181
}
82-
loadSkills(skills:ISkill[]):FormArray{
82+
loadSkills(skills:ISkill[]):FormArray{
8383
letformArr=newFormArray([]);
84-
skills.forEach(s=>{
84+
skills.forEach(s=>{
8585
formArr.push(this.addSkill());
8686
});
8787
returnformArr;
@@ -93,28 +93,34 @@ export class PutEmployeeComponent implements OnInit {
9393
}else{
9494
//submit form
9595
console.log(this.employeeForm);
96-
if(this.editId){
97-
this.ds.putEmployee(this.employeeForm.value,this.editId).subscribe(
96+
if(this.editId){
97+
this.ds.putEmployee(this.employeeForm.value,this.editId).subscribe(
9898
(data)=>{
9999
this.employee=data;
100100
this.loadEmployee(this.employee);
101101
},
102-
(err)=>console.log(err)
102+
(err)=>console.log(err),
103+
()=>{
104+
this.employeeForm.markAsUntouched();
105+
alert("Data has been saved!");
106+
}
103107
);
104-
}else{
108+
}else{
105109
this.ds.postEmployee(this.employeeForm.value).subscribe(
106110
(data)=>this.employee=data,
107-
(err)=>console.log(err)
111+
(err)=>console.log(err),
112+
()=>{
113+
this.employeeForm.markAsUntouched();
114+
alert("Data has been saved!");
115+
}
108116
);
109117
}
110-
this.employeeForm.markAsUntouched();
111-
alert("Data has been saved!")
112118
}
113119
}
114120
onAddSkillBtn_Click(){
115121
(this.employeeForm.get('skills')asFormArray).push(this.addSkill());
116122
}
117-
onDelSkill_Click(index:number){
123+
onDelSkill_Click(index:number){
118124
letskillSet=(this.employeeForm.get('skills')asFormArray);
119125
skillSet.removeAt(index);
120126
skillSet.markAsTouched();
@@ -126,7 +132,7 @@ export class PutEmployeeComponent implements OnInit {
126132
constfc=fg.get(key);
127133

128134
this.formErr[key]='';
129-
if(fc.touched||fc.dirty||fc.value!='')
135+
if(fc.touched||fc.dirty||fc.value!='')
130136
for(consterrKeyinfc.errors){
131137
if(Object.prototype.hasOwnProperty.call(fc.errors,errKey)){
132138
consterrMsg=this.validationMessages[key][errKey];

‎src/app/service/employee-service.service.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import { catchError } from 'rxjs/operators'
99
})
1010
exportclassEmployeeDataService{
1111
//employees:IEmployee[];
12-
baseUrl:string='http://localhost:3000/employees/';
13-
apiUrl:string='http://localhost:8081/Employee/';
12+
baseUrl:string='http://localhost:3000/employees/';//local fake json-server
13+
apiUrl:string='http://localhost:8081/Employee/';//local hosted api link
1414
constructor(privatehttp:HttpClient){}
1515

1616
getEmployees():Observable<IEmployee[]>{
@@ -36,7 +36,7 @@ export class EmployeeDataService {
3636
}).pipe(catchError(this.handleError));
3737
}
3838
deleteEmployee(id:number):Observable<void>{
39-
returnthis.http.get<void>(this.baseUrl+id)
39+
returnthis.http.delete<void>(this.apiUrl+id)
4040
.pipe(catchError(this.handleError));
4141
}
4242

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp