Last active
December 8, 2019 01:58
-
-
Save adrianlemess/f03a756b95c9953b07ca955dd33fef83 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Component({ | |
selector: 'app-home', | |
template: ` | |
<h2>All Lessons</h2> | |
<h4>Total Lessons: {{lessons?.length}}</h4> | |
<div class="lessons-list-container v-h-center-block-parent"> | |
<table class="table lessons-list card card-strong"> | |
<tbody> | |
<tr *ngFor="let lesson of lessons" (click)="selectLesson(lesson)"> | |
<td class="lesson-title"> {{lesson.description}} </td> | |
<td class="duration"> | |
<i class="md-icon duration-icon">access_time</i> | |
<span>{{lesson.duration}}</span> | |
</td> | |
</tr> | |
</tbody> | |
</table> | |
</div> | |
`, | |
styleUrls: ['./home.component.css'] | |
}) | |
export class HomeComponent implements OnInit { | |
lessons: Lesson[]; | |
constructor(private lessonsService: LessonsService) { | |
} | |
ngOnInit() { | |
this.lessonsService.findAllLessons() | |
.subscribe( | |
lessons => this.allLessons = lessons | |
); | |
} | |
selectLesson(lesson) { | |
... | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {Component, OnInit, Input, EventEmitter, Output} from '@angular/core'; | |
import {Lesson} from "../shared/model/lesson"; | |
@Component({ | |
selector: 'lessons-list', | |
template: ` | |
<table class="table lessons-list card card-strong"> | |
<tbody> | |
<tr *ngFor="let lesson of lessons" (click)="selectLesson(lesson)"> | |
<td class="lesson-title"> {{lesson.description}} </td> | |
<td class="duration"> | |
<i class="md-icon duration-icon">access_time</i> | |
<span>{{lesson.duration}}</span> | |
</td> | |
</tr> | |
</tbody> | |
</table> | |
`, | |
styleUrls: ['./lessons-list.component.css'] | |
}) | |
export class LessonsListComponent { | |
@Input() | |
lessons: Lesson[]; | |
@Output('lesson') | |
lessonEmitter = new EventEmitter<Lesson>(); | |
selectLesson(lesson:Lesson) { | |
this.lessonEmitter.emit(lesson); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Component, OnInit } from '@angular/core'; | |
import {LessonsService} from "../shared/model/lessons.service"; | |
import {Lesson} from "../shared/model/lesson"; | |
@Component({ | |
selector: 'app-home', | |
template: ` | |
<h2>All Lessons</h2> | |
<h4>Total Lessons: {{lessons?.length}}</h4> | |
<div class="lessons-list-container v-h-center-block-parent"> | |
<lessons-list [lessons]="lessons" (lesson)="selectLesson($event)"></lessons-list> | |
</div> | |
`, | |
styleUrls: ['./home.component.css'] | |
}) | |
export class HomeComponent implements OnInit { | |
lessons: Lesson[]; | |
constructor(private lessonsService: LessonsService) { | |
} | |
ngOnInit() { | |
... | |
} | |
selectLesson(lesson) { | |
... | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment