Skip to content

Commit 51202b1

Browse files
committed
Angular Forms In Depth Course
2 parents 4c923bc + 746f50a commit 51202b1

28 files changed

+302
-77
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
This repository contains the code of the [Angular Forms In Depth](https://angular-university.io/course/angular-forms-course) video course.
55

6+
This course repository is updated to Angular v11:
7+
68
![Angular Forms In Depth](https://angular-university.s3-us-west-1.amazonaws.com/course-images/angular-forms-course-small.jpg)
79

810

package-lock.json

Lines changed: 29 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"@angular/router": "11.0.0",
2727
"core-js": "^2.4.1",
2828
"express": "^4.16.2",
29+
"express-fileupload": "^1.2.0",
2930
"moment": "^2.22.2",
3031
"rxjs": "6.5.4",
3132
"tslib": "^2.0.0",

server/file-upload.route.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
import {Request, Response} from 'express';
3+
4+
5+
export function onFileupload(req:Request, res: Response) {
6+
7+
let file = req['files'].thumbnail;
8+
9+
console.log("File uploaded: ", file.name);
10+
11+
setTimeout(() => {
12+
res.status(200).json({message: 'File uploaded successfully.'});
13+
}, 2000)
14+
15+
16+
17+
}

server/server.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,14 @@ import {Application} from "express";
55
import {getAllCourses, getCourseById} from "./get-courses.route";
66
import {searchLessons} from "./search-lessons.route";
77
import {getCourseCategories} from './course-categories.route';
8+
import {onFileupload} from './file-upload.route';
9+
const fileUpload = require('express-fileupload');
810

911

1012
const app: Application = express();
1113

14+
app.use(fileUpload());
15+
1216

1317
app.route('/api/courses').get(getAllCourses);
1418

@@ -18,6 +22,8 @@ app.route('/api/lessons').get(searchLessons);
1822

1923
app.route('/api/course-categories').get(getCourseCategories);
2024

25+
app.route('/api/thumbnail-upload').post(onFileupload);
26+
2127

2228
const httpServer:any = app.listen(9000, () => {
2329
console.log("HTTP REST API Server running at http://localhost:" + httpServer.address().port);

src/app/address-form/address-form.component.html

Whitespace-only changes.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
.address-error {
3+
color:red;
4+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import {Component, Input, OnDestroy, OnInit} from '@angular/core';
2+
import {
3+
AbstractControl,
4+
ControlValueAccessor,
5+
FormBuilder, FormGroup,
6+
NG_VALIDATORS,
7+
NG_VALUE_ACCESSOR,
8+
Validator,
9+
Validators
10+
} from '@angular/forms';
11+
import {noop, Subscription} from 'rxjs';
12+
13+
@Component({
14+
selector: 'address-form',
15+
templateUrl: './address-form.component.html',
16+
styleUrls: ['./address-form.component.scss']
17+
})
18+
export class AddressFormComponent {
19+
20+
}
21+
22+
23+

src/app/app.module.ts

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {BrowserModule} from '@angular/platform-browser';
2-
import {NgModule} from '@angular/core';
2+
import {forwardRef, NgModule} from '@angular/core';
33

44
import {AppRoutingModule} from './app-routing.module';
55
import {AppComponent} from './app.component';
@@ -28,11 +28,20 @@ import {CoursesService} from "./services/courses.service";
2828
import {HttpClientModule} from "@angular/common/http";
2929
import {CourseResolver} from "./services/course.resolver";
3030
import { CourseDialogComponent } from './course-dialog/course-dialog.component';
31-
import {FormsModule, ReactiveFormsModule} from "@angular/forms";
32-
import {MatMomentDateModule} from "@angular/material-moment-adapter";
31+
import {FormsModule, ReactiveFormsModule} from '@angular/forms';
3332
import {LoginComponent} from './login/login.component';
3433
import { CreateCourseComponent } from './create-course/create-course.component';
34+
import {MatNativeDateModule} from '@angular/material/core';
3535
import {PasswordStrengthDirective} from './directives/password-strength.directive';
36+
import {MatRadioModule} from '@angular/material/radio';
37+
import {MatCheckboxModule} from '@angular/material/checkbox';
38+
import {CreateCourseStep2Component} from './create-course/create-course-step-2/create-course-step-2.component';
39+
import {MatStepperModule} from '@angular/material/stepper';
40+
import { AddressFormComponent } from './address-form/address-form.component';
41+
import {CreateCourseStep3Component} from './create-course/create-course-step-3/create-course-step-3.component';
42+
import {CreateCourseStep1Component} from './create-course/create-course-step-1/create-course-step-1.component';
43+
import {FileUploadComponent} from './file-upload/file-upload.component';
44+
import {MatProgressBarModule} from '@angular/material/progress-bar';
3645

3746
@NgModule({
3847
declarations: [
@@ -44,7 +53,12 @@ import {PasswordStrengthDirective} from './directives/password-strength.directiv
4453
CourseDialogComponent,
4554
LoginComponent,
4655
CreateCourseComponent,
47-
PasswordStrengthDirective
56+
PasswordStrengthDirective,
57+
CreateCourseStep1Component,
58+
CreateCourseStep2Component,
59+
CreateCourseStep3Component,
60+
AddressFormComponent,
61+
FileUploadComponent
4862
],
4963
imports: [
5064
BrowserModule,
@@ -67,7 +81,11 @@ import {PasswordStrengthDirective} from './directives/password-strength.directiv
6781
AppRoutingModule,
6882
MatSelectModule,
6983
MatDatepickerModule,
70-
MatMomentDateModule,
84+
MatNativeDateModule,
85+
MatRadioModule,
86+
MatCheckboxModule,
87+
MatStepperModule,
88+
MatProgressBarModule,
7189
FormsModule,
7290
ReactiveFormsModule
7391
],

src/app/course-dialog/course-dialog.component.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import {Component, Inject, OnInit, ViewEncapsulation} from '@angular/core';
1+
import {Component, Inject, OnInit} from '@angular/core';
22
import { MAT_DIALOG_DATA, MatDialogRef } from "@angular/material/dialog";
33
import {Course} from "../model/course";
44
import {FormBuilder, Validators, FormGroup} from "@angular/forms";
5-
import * as moment from 'moment';
65

76
@Component({
87
selector: 'course-dialog',
@@ -26,7 +25,7 @@ export class CourseDialogComponent implements OnInit {
2625
this.form = fb.group({
2726
description: [description, Validators.required],
2827
category: [category, Validators.required],
29-
releasedAt: [moment(), Validators.required],
28+
releasedAt: [new Date(), Validators.required],
3029
longDescription: [longDescription,Validators.required]
3130
});
3231

src/app/create-course/create-course-step-1/create-course-step-1.component.html

Whitespace-only changes.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
3+
textarea {
4+
max-height: 20px;
5+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import {Component, OnInit} from '@angular/core';
2+
import {FormBuilder, FormGroup, Validators} from '@angular/forms';
3+
import {CoursesService} from '../../services/courses.service';
4+
import {Observable} from 'rxjs';
5+
import {filter} from 'rxjs/operators';
6+
7+
@Component({
8+
selector: 'create-course-step-1',
9+
templateUrl: './create-course-step-1.component.html',
10+
styleUrls: ['./create-course-step-1.component.scss']
11+
})
12+
export class CreateCourseStep1Component implements OnInit {
13+
14+
15+
ngOnInit() {
16+
17+
18+
}
19+
20+
}

src/app/create-course/create-course-step-2/create-course-step-2.component.html

Whitespace-only changes.

src/app/create-course/create-course-step-2/create-course-step-2.component.scss

Whitespace-only changes.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import {Component, OnInit} from '@angular/core';
2+
import {FormBuilder, FormGroup, Validators} from '@angular/forms';
3+
4+
5+
@Component({
6+
selector: 'create-course-step-2',
7+
templateUrl: 'create-course-step-2.component.html',
8+
styleUrls: ['create-course-step-2.component.scss']
9+
})
10+
export class CreateCourseStep2Component implements OnInit {
11+
12+
13+
ngOnInit() {
14+
15+
16+
17+
}
18+
19+
}

src/app/create-course/create-course-step-3/create-course-step-3.component.html

Whitespace-only changes.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
.add-lessons-form {
3+
margin-bottom: 40px;
4+
display: flex;
5+
align-items: center;
6+
flex-direction: column;
7+
8+
}
9+
10+
.lesson-form-row {
11+
display: flex;
12+
13+
mat-form-field {
14+
margin-right: 10px;
15+
}
16+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import {Component} from '@angular/core';
2+
import {FormArray, FormBuilder, FormGroup, Validators} from '@angular/forms';
3+
4+
5+
@Component({
6+
selector: 'create-course-step-3',
7+
templateUrl: 'create-course-step-3.component.html',
8+
styleUrls: ['create-course-step-3.component.scss']
9+
})
10+
export class CreateCourseStep3Component {
11+
12+
13+
14+
}

src/app/create-course/create-course.component.css

Lines changed: 0 additions & 10 deletions
This file was deleted.
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11

2-
<div class="create-course-panel">
2+
<div class="create-course-panel data-form">
33

44
<h2 class="title">Create New Course</h2>
55

66

7+
78
</div>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
h2 {
3+
font-family: "Roboto";
4+
}
5+
6+
.data-form {
7+
max-width: 600px;
8+
margin: 0 auto;
9+
}
10+
11+
12+
.stepper-buttons button{
13+
margin-right: 5px;
14+
}
Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,26 @@
11
import { Component, OnInit } from '@angular/core';
2+
import {STEPPER_GLOBAL_OPTIONS} from '@angular/cdk/stepper';
3+
4+
5+
26

37
@Component({
48
selector: 'create-course',
59
templateUrl: './create-course.component.html',
6-
styleUrls: ['./create-course.component.css']
10+
styleUrls: ['./create-course.component.scss']
711
})
812
export class CreateCourseComponent implements OnInit {
913

10-
constructor() { }
1114

12-
ngOnInit(): void {
15+
16+
17+
ngOnInit() {
18+
19+
20+
1321
}
1422

23+
24+
25+
1526
}

src/app/file-upload/file-upload.component.html

Whitespace-only changes.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
2+
.file-input {
3+
display: none;
4+
}
5+
6+
.file-upload {
7+
display: flex;
8+
align-items: flex-end;
9+
}
10+
11+
.upload-btn {
12+
margin-left: 10px;
13+
margin-bottom:15px;
14+
}
15+
16+
.progress-bar {
17+
margin-bottom: 10px;
18+
}

0 commit comments

Comments
 (0)