mirror of
https://github.com/ChronosX88/InstructorsListAppTA.git
synced 2024-12-04 22:52:19 +00:00
[ui] feat: Implement loading instructors list
This commit is contained in:
parent
c487612839
commit
e9f11bd288
@ -17,9 +17,9 @@
|
||||
</table>
|
||||
<div style="text-align: center;"><h1>Instructor Details</h1>
|
||||
<br>
|
||||
<label><h5 style="text-align: initial">First Name</h5><input type="text" style="margin-right: 20px"></label>
|
||||
<label><h5 style="text-align: initial">Middle Name</h5><input type="text" style="margin-right: 20px"></label>
|
||||
<label><h5 style="text-align: initial">Last Name</h5><input type="text"></label>
|
||||
<label><h5 style="text-align: initial">First Name</h5><input type="text" style="margin-right: 20px" [(ngModel)]="changingInstructor.firstName"></label>
|
||||
<label><h5 style="text-align: initial">Middle Name</h5><input type="text" style="margin-right: 20px" [(ngModel)]="changingInstructor.middleName"></label>
|
||||
<label><h5 style="text-align: initial">Last Name</h5><input type="text" [(ngModel)]="changingInstructor.lastName"></label>
|
||||
<br>
|
||||
<button type="button" class="btn btn-primary">ADD/SAVE</button>
|
||||
</div>
|
||||
|
@ -1,22 +1,26 @@
|
||||
import { Component, Inject } from '@angular/core';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { Instructor } from '../models/instructor';
|
||||
import { InstructorsHttpService } from '../services/instructors-http-service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-home',
|
||||
templateUrl: './home.component.html',
|
||||
providers: [InstructorsHttpService]
|
||||
})
|
||||
export class HomeComponent {
|
||||
public instructors: any[] = [{id: "1", firstName: "Test", lastName: "Testov"}];
|
||||
public instructors: Instructor[];
|
||||
private changingInstructor: Instructor = new Instructor();
|
||||
|
||||
constructor(http: HttpClient, @Inject('BASE_URL') baseUrl: string) {
|
||||
/*http.get<Instructor[]>(baseUrl + 'api/v1/instructors').subscribe(result => {
|
||||
this.instructors = result;
|
||||
}, error => console.error(error));*/
|
||||
constructor(private instructorsService: InstructorsHttpService) {}
|
||||
|
||||
ngOnInit() {
|
||||
this.loadInstructors()
|
||||
}
|
||||
}
|
||||
|
||||
interface Instructor {
|
||||
id: string,
|
||||
firstName: string,
|
||||
lastName: string
|
||||
private loadInstructors() {
|
||||
this.instructorsService.getInstructors().subscribe(result => {
|
||||
this.instructors = result;
|
||||
})
|
||||
}
|
||||
}
|
7
ClientApp/src/app/models/instructor.ts
Normal file
7
ClientApp/src/app/models/instructor.ts
Normal file
@ -0,0 +1,7 @@
|
||||
export class Instructor {
|
||||
constructor(
|
||||
public id?: string,
|
||||
public firstName?: string,
|
||||
public middleName?: string,
|
||||
public lastName?: string) { }
|
||||
}
|
24
ClientApp/src/app/services/instructors-http-service.ts
Normal file
24
ClientApp/src/app/services/instructors-http-service.ts
Normal file
@ -0,0 +1,24 @@
|
||||
import { Injectable, Inject } from '@angular/core';
|
||||
import { HttpClient} from '@angular/common/http';
|
||||
import { Instructor } from '../models/instructor';
|
||||
|
||||
@Injectable()
|
||||
export class InstructorsHttpService {
|
||||
constructor(private http: HttpClient, @Inject('BASE_URL') private baseUrl: string) {}
|
||||
|
||||
getInstructors() {
|
||||
return this.http.get<Instructor[]>(this.baseUrl + "api/v1/instructors")
|
||||
}
|
||||
|
||||
createInstructor(instructor: Instructor) {
|
||||
return this.http.post(this.baseUrl + "api/v1/instructors/add", instructor)
|
||||
}
|
||||
|
||||
updateInstructor(instructor: Instructor) {
|
||||
return this.http.put(this.baseUrl + "api/v1/instructors/" + instructor.id, instructor)
|
||||
}
|
||||
|
||||
deleteInstructor(id: string) {
|
||||
return this.http.delete(this.baseUrl + "api/v1/instructors/" + id)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user