Skip to content

Commit 6fd4276

Browse files
committed
add eventlist const
1 parent 4cb4fe7 commit 6fd4276

File tree

3 files changed

+326
-365
lines changed

3 files changed

+326
-365
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"core-js": "^2.5.4",
2424
"ngf-bootstrap": "0.0.5",
2525
"rxjs": "~6.3.3",
26+
"toastr": "^2.1.4",
2627
"tslib": "^1.9.0",
2728
"zone.js": "~0.8.26"
2829
},

src/app/events/events-list.component.ts

Lines changed: 1 addition & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1 @@
1-
import { Component } from "@angular/core";
2-
import { EventService } from "./shared/event.service";
3-
4-
/*
5-
* [event] -> to pass data from one component to the child
6-
* eventClick -> come from the child event emitter (event-thumbnail)
7-
* -> when it's fired call the handleEventClicked in the parent (events-list)
8-
* -> $event -> data emitted by the thumbnail (foo)
9-
*
10-
* ngfor -> is a structural directive, it means it's going to change the shape of the dom. Add or remove html.
11-
* -> the expression inside create a LOCAL variable, ngfor will duplicate the element as many times as
12-
* -> needed.
13-
* -> Not only the element can be duplicate
14-
*
15-
* */
16-
@Component({
17-
selector: "events-list",
18-
template: `
19-
<div>
20-
<h1>Upcoming event</h1>
21-
<hr />
22-
<div class="row">
23-
<div *ngFor="let event of events; trackBy: trackByFn" class="col-md-5">
24-
<event-thumbnail #thumbnail [event]="event"></event-thumbnail>
25-
</div>
26-
</div>
27-
</div>
28-
`
29-
})
30-
export class EventsListComponent {
31-
/*
32-
* Same as :
33-
* public constructor() {
34-
* this.enventService = eventService;
35-
* }
36-
* */
37-
public constructor(private enventService: EventService) {}
38-
public trackByFn(index: any, item: any): any {
39-
return index;
40-
}
41-
}
1+
import { Component, OnInit } from "@angular/core";import { EventService } from "./shared/event.service";import { ToastrService } from "../common/toastr.service";/* * [event] -> to pass data from one component to the child * eventClick -> come from the child event emitter (event-thumbnail) * -> when it's fired call the handleEventClicked in the parent (events-list) * -> $event -> data emitted by the thumbnail (foo) * * ngfor -> is a structural directive, it means it's going to change the shape of the dom. Add or remove html. * -> the expression inside create a LOCAL variable, ngfor will duplicate the element as many times as * -> needed. * -> Not only the element can be duplicate * * */@Component({ selector: "events-list", template: ` <div> <h1>Upcoming event</h1> <hr /> <div class="row"> <div *ngFor="let event of events; trackBy: trackByFn" class="col-md-5"> <event-thumbnail (click)="handleThumbnailClick(event.name)" #thumbnail [event]="event" ></event-thumbnail> </div> </div> </div> `})export class EventsListComponent implements OnInit { /* * Same as : * public constructor() { * this.enventService = eventService; * } * */ public events: any; public constructor( private eventService: EventService, private toastr: ToastrService ) {} /* * When using ngOnInit() it's better to implement the OnInit Interface to save some * angular compilation * */ public ngOnInit(): void { this.events = this.eventService.getEvents(); } public handleThumbnailClick(eventName: string): any { this.toastr.success(eventName); } public trackByFn(index: any, item: any): any { return index; }}

0 commit comments

Comments
 (0)