Skip to content

Commit 3088bee

Browse files
author
Your Name
committed
typescript course ongoing
1 parent ab00738 commit 3088bee

File tree

5 files changed

+58
-5
lines changed

5 files changed

+58
-5
lines changed

client/src/app/app.component.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
1-
import { Component } from '@angular/core';
1+
import {Component, OnInit} from '@angular/core';
2+
import {CoursesService} from "./services/courses.service";
23

34
@Component({
45
selector: 'app-root',
56
templateUrl: './app.component.html',
67
styleUrls: ['./app.component.css']
78
})
8-
export class AppComponent {
9-
title = 'app works!';
9+
export class AppComponent implements OnInit {
10+
11+
constructor(private coursesService:CoursesService) {
12+
13+
}
14+
15+
ngOnInit() {
16+
this.coursesService.loadCourseDetail(1);
17+
}
18+
1019
}

client/src/app/app.module.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { HttpModule } from '@angular/http';
55

66
import { AppComponent } from './app.component';
77
import { CourseDetailComponent } from './course-detail/course-detail.component';
8+
import {CoursesService} from "./services/courses.service";
89

910
@NgModule({
1011
declarations: [
@@ -16,7 +17,7 @@ import { CourseDetailComponent } from './course-detail/course-detail.component';
1617
FormsModule,
1718
HttpModule
1819
],
19-
providers: [],
20+
providers: [CoursesService],
2021
bootstrap: [AppComponent]
2122
})
2223
export class AppModule { }

client/src/app/course-detail/course-detail.component.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,14 @@ import { Component, OnInit } from '@angular/core';
77
})
88
export class CourseDetailComponent implements OnInit {
99

10-
constructor() { }
10+
constructor() {
11+
12+
13+
}
1114

1215
ngOnInit() {
16+
17+
1318
}
1419

1520
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/* tslint:disable:no-unused-variable */
2+
3+
import { TestBed, async, inject } from '@angular/core/testing';
4+
import { CoursesService } from './courses.service';
5+
6+
describe('Service: Courses', () => {
7+
beforeEach(() => {
8+
TestBed.configureTestingModule({
9+
providers: [CoursesService]
10+
});
11+
});
12+
13+
it('should ...', inject([CoursesService], (service: CoursesService) => {
14+
expect(service).toBeTruthy();
15+
}));
16+
});
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { Injectable } from '@angular/core';
2+
import {Http} from "@angular/http";
3+
import {Observable} from "rxjs";
4+
import {CourseDetail} from "../../../../shared/model/course-detail";
5+
6+
7+
8+
@Injectable()
9+
export class CoursesService {
10+
11+
constructor(private http:Http) { }
12+
13+
14+
loadCourseDetail(courseId: number) :Observable<CourseDetail> {
15+
16+
return this.http.get(`/api/courses/${courseId}`)
17+
.map(res => res.json());
18+
19+
}
20+
21+
22+
}

0 commit comments

Comments
 (0)