Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 7 additions & 15 deletions src/app/app.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,13 @@


<div class="courses">
<!-- there is an instance of the course card component for each card -->
<!-- we have defined course : Course as an attribute of course card component -->
<!-- courseSelected is not a standard dom event -->
<course-card (courseSelected)="onCourseSelected($event)" [course]="coreCourse"></course-card>
<course-card (courseSelected)="onCourseSelected($event)" [course]="rjsCourse"></course-card>
<course-card (courseSelected)="onCourseSelected($event)" [course]="ngrxCourse"></course-card>
<!-- we can see that the course card is visible because we have added this html in our AppComponent template -->

<div class="course-card">

<div class="course-title">
Angular Core Deep Dive
</div>
<img width="300" alt="Angular Logo"
src="https://s3-us-west-1.amazonaws.com/angular-university/course-images/angular-core-in-depth-small.png">

<div class="course-description">
A detailed walk-through of the most important part of Angular - the Core and Common modules.
</div>

</div>

</div>


20 changes: 19 additions & 1 deletion src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,31 @@
import { Component } from '@angular/core';
import {COURSES} from '../db-data';
import { Course } from './model/course';

@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {

// this is how we make available the course objects so that we can display different course cards
// now these are available in the AppComponent template
// { this is how the elements of array COURSES look like
// id: 1,
// description: "Angular Core Deep Dive",
// iconUrl: 'https://s3-us-west-1.amazonaws.com/angular-university/course-images/angular-core-in-depth-small.png',
// longDescription: "A detailed walk-through of the most important part of Angular - the Core and Common modules",
// category: 'INTERMEDIATE',
// lessonsCount: 10
// }
// these are defined in db-data.ts
// bexause we are displaying these in the template of the app component
coreCourse = COURSES[0];
rjsCourse = COURSES[1];
ngrxCourse = COURSES[2];
onCourseSelected(course: Course) {
console.log("App component - click event bubbled...", course)
}


}
4 changes: 3 additions & 1 deletion src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ import { NgModule } from '@angular/core';

import { AppComponent } from './app.component';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { CourseCardComponent } from './course-card/course-card.component';

@NgModule({
declarations: [
AppComponent
AppComponent,
CourseCardComponent
],
imports: [
BrowserModule,
Expand Down
1 change: 1 addition & 0 deletions src/app/course-card/course-card.component.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/* we will */
15 changes: 15 additions & 0 deletions src/app/course-card/course-card.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

<div class="course-card">

<div class="course-title">
<!-- Angular Core Deep Dive -->
{{ course.description }}
</div>
<img width="300" alt="Angular Logo"
[src]="course.iconUrl">
<div class="course-description">
{{ course.longDescription }}
</div>
<button (click)="onCourseViewed()">View Course</button>

</div>
26 changes: 26 additions & 0 deletions src/app/course-card/course-card.component.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';

import { CourseCardComponent } from './course-card.component';

describe('CourseCardComponent', () => {
let component: CourseCardComponent;
let fixture: ComponentFixture<CourseCardComponent>;

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ CourseCardComponent ]
})
.compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(CourseCardComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
// another comment
30 changes: 30 additions & 0 deletions src/app/course-card/course-card.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { Component, EventEmitter, OnInit , Input, Output} from '@angular/core';
import { COURSES } from '../../db-data';
import { Course } from '../model/course';

@Component({
selector: 'course-card', // defines html tag
templateUrl: './course-card.component.html',
styleUrls: ['./course-card.component.css']
})
export class CourseCardComponent implements OnInit {
//need to import Input or it will not compile!!
@Input()
course: Course; // from the model folder

// emit custom event (note the type Course passed)
@Output()
courseSelected = new EventEmitter<Course>();

constructor() { }

ngOnInit(): void {
}

onCourseViewed() {
console.log("card component button clicked");
this.courseSelected.emit(this.course);
}

}
// comment