Skip to content
This repository was archived by the owner on Apr 17, 2020. It is now read-only.

Commit c27b1a8

Browse files
author
Your Name
committed
preparing new lessons
1 parent 112d4a3 commit c27b1a8

11 files changed

+158
-9
lines changed

src/app/app.module.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ import { CourseDetailComponent } from './course-detail/course-detail.component';
1616
import {CoursesService} from "./services/courses.service";
1717
import { CoursesListComponent } from './courses-list/courses-list.component';
1818
import { CourseDetailHeaderComponent } from './course-detail-header/course-detail-header.component';
19+
import { NewsletterComponent } from './newsletter/newsletter.component';
20+
import {NewsletterService} from "./services/newsletter.service";
21+
import {UserService} from "./services/user.service";
1922

2023
@NgModule({
2124
declarations: [
@@ -27,7 +30,8 @@ import { CourseDetailHeaderComponent } from './course-detail-header/course-detai
2730
HomeComponent,
2831
CourseDetailComponent,
2932
CoursesListComponent,
30-
CourseDetailHeaderComponent
33+
CourseDetailHeaderComponent,
34+
NewsletterComponent
3135
],
3236
imports: [
3337
BrowserModule,
@@ -37,7 +41,9 @@ import { CourseDetailHeaderComponent } from './course-detail-header/course-detai
3741
RouterModule.forRoot(routerConfig),
3842
],
3943
providers: [
40-
CoursesService
44+
CoursesService,
45+
NewsletterService,
46+
UserService
4147
],
4248
bootstrap: [AppComponent]
4349
})

src/app/course-detail-header/course-detail-header.component.html

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,4 @@ <h2>{{course?.description}}</h2>
44
<h5>Total lessons: {{lessons?.length}}</h5>
55

66

7-
<fieldset class="newsletter">
8-
<legend>Newsletter</legend>
9-
<form>
10-
<input type="email" name="email" placeholder="Enter your Email">
11-
<input type="button" class="button button-primary" value="Subscribe">
12-
</form>
13-
</fieldset>
7+
<newsletter></newsletter>

src/app/newsletter/newsletter.component.css

Whitespace-only changes.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<fieldset class="newsletter">
2+
<legend>Newsletter</legend>
3+
4+
<h5>Hello {{(userService.user$ | async)?.firstName }},
5+
enter your name below to subscribe:</h5>
6+
7+
<form>
8+
<input type="email" name="email" placeholder="Enter your Email">
9+
<input #email type="button" class="button button-primary" value="Subscribe"
10+
(click)="subscribe(email.value)">
11+
</form>
12+
</fieldset>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
2+
3+
import { NewsletterComponent } from './newsletter.component';
4+
5+
describe('NewsletterComponent', () => {
6+
let component: NewsletterComponent;
7+
let fixture: ComponentFixture<NewsletterComponent>;
8+
9+
beforeEach(async(() => {
10+
TestBed.configureTestingModule({
11+
declarations: [ NewsletterComponent ]
12+
})
13+
.compileComponents();
14+
}));
15+
16+
beforeEach(() => {
17+
fixture = TestBed.createComponent(NewsletterComponent);
18+
component = fixture.componentInstance;
19+
fixture.detectChanges();
20+
});
21+
22+
it('should create', () => {
23+
expect(component).toBeTruthy();
24+
});
25+
});
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import {Component, OnInit} from '@angular/core';
2+
import {UserService} from "../services/user.service";
3+
import {NewsletterService} from "../services/newsletter.service";
4+
5+
@Component({
6+
selector: 'newsletter',
7+
templateUrl: './newsletter.component.html',
8+
styleUrls: ['./newsletter.component.css']
9+
})
10+
export class NewsletterComponent {
11+
12+
constructor(private userService: UserService,
13+
private newsletterService: NewsletterService) {
14+
15+
}
16+
17+
subscribe(email:string) {
18+
this.newsletterService.subscribeToNewsletter(email);
19+
}
20+
21+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { TestBed, inject } from '@angular/core/testing';
2+
3+
import { NewsletterService } from './newsletter.service';
4+
5+
describe('NewsletterService', () => {
6+
beforeEach(() => {
7+
TestBed.configureTestingModule({
8+
providers: [NewsletterService]
9+
});
10+
});
11+
12+
it('should ...', inject([NewsletterService], (service: NewsletterService) => {
13+
expect(service).toBeTruthy();
14+
}));
15+
});
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { Injectable } from '@angular/core';
2+
import {Http} from "@angular/http";
3+
4+
@Injectable()
5+
export class NewsletterService {
6+
7+
8+
constructor(private http:Http) { }
9+
10+
subscribeToNewsletter(email: string) {
11+
12+
}
13+
14+
15+
}

src/app/services/user.service.spec.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { TestBed, inject } from '@angular/core/testing';
2+
3+
import { UserService } from './user.service';
4+
5+
describe('UserService', () => {
6+
beforeEach(() => {
7+
TestBed.configureTestingModule({
8+
providers: [UserService]
9+
});
10+
});
11+
12+
it('should ...', inject([UserService], (service: UserService) => {
13+
expect(service).toBeTruthy();
14+
}));
15+
});

src/app/services/user.service.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import {Injectable, OnInit} from '@angular/core';
2+
import {Observable, BehaviorSubject} from "rxjs";
3+
import {User} from "../shared/model/user";
4+
5+
6+
export const ANONYMOUS_USER : User = {
7+
firstName: ' Anonymous',
8+
lastName: ''
9+
}
10+
11+
12+
@Injectable()
13+
export class UserService implements OnInit {
14+
15+
private subject = new BehaviorSubject<User>(ANONYMOUS_USER);
16+
17+
user$: Observable<User> = this.subject.asObservable();
18+
19+
20+
constructor() {
21+
22+
23+
}
24+
25+
26+
ngOnInit() {
27+
28+
29+
30+
31+
}
32+
33+
34+
35+
}

0 commit comments

Comments
 (0)