Skip to content
This repository was archived by the owner on Oct 14, 2019. It is now read-only.

Commit 4ad8b2b

Browse files
author
Your Name
committed
Angular and Firebase App
1 parent 090f447 commit 4ad8b2b

File tree

2 files changed

+21
-12
lines changed

2 files changed

+21
-12
lines changed

src/app/lesson-detail/lesson-detail.component.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ export class LessonDetailComponent implements OnInit {
2828
this.route.params.switchMap(
2929
params => {
3030

31-
32-
3331
const lessonUrl = params['id'];
3432

3533
return this.lessonsService.findLessonByUrl(lessonUrl);
@@ -42,24 +40,23 @@ export class LessonDetailComponent implements OnInit {
4240
}
4341

4442
next() {
45-
4643
this.lessonsService.loadNextLesson(this.lesson.courseId,this.lesson.$key)
47-
.subscribe(this.nativateToLesson.bind(this));
48-
44+
.subscribe(this.navigateToLesson.bind(this));
4945
}
5046

5147
previous() {
52-
5348
this.lessonsService.loadPreviousLesson(this.lesson.courseId,this.lesson.$key)
54-
.subscribe(this.nativateToLesson.bind(this));
49+
.subscribe(this.navigateToLesson.bind(this));
50+
}
5551

5652

53+
navigateToLesson(lesson:Lesson) {
54+
this.router.navigate(['lessons', lesson.url]);
5755
}
5856

5957

60-
nativateToLesson(lesson:Lesson) {
6158

62-
this.router.navigate(['lessons', lesson.url]);
63-
}
59+
60+
6461

6562
}

src/app/shared/model/lessons.service.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export class LessonsService {
3232
loadNextLesson(courseId:string, lessonId:string):Observable<Lesson> {
3333
return this.db.list(`lessonsPerCourse/${courseId}`, {
3434
query: {
35-
orderByKey: true,
35+
orderByKey:true,
3636
startAt: lessonId,
3737
limitToFirst: 2
3838
}
@@ -46,15 +46,27 @@ export class LessonsService {
4646
loadPreviousLesson(courseId:string, lessonId:string):Observable<Lesson> {
4747
return this.db.list(`lessonsPerCourse/${courseId}`, {
4848
query: {
49-
orderByKey: true,
49+
orderByKey:true,
5050
endAt: lessonId,
5151
limitToLast: 2
5252
}
5353
})
5454
.map(results => results[0].$key)
5555
.switchMap(lessonId => this.db.object(`lessons/${lessonId}`))
5656
.map(Lesson.fromJson);
57+
5758
}
5859

5960

6061
}
62+
63+
64+
65+
66+
67+
68+
69+
70+
71+
72+

0 commit comments

Comments
 (0)