Skip to content

Commit cbe772a

Browse files
committed
Angular Forms In Depth Course
2 parents 665d208 + 746f50a commit cbe772a

29 files changed

+1100
-369
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: 812 additions & 286 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,14 @@
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",
3233
"zone.js": "~0.10.3"
3334
},
3435
"devDependencies": {
35-
"@angular-devkit/build-angular": "~0.1100.1",
36+
"@angular-devkit/build-angular": "^0.1100.1",
3637
"@angular-devkit/schematics": "^11.0.1",
3738
"@angular/cli": "^11.0.1",
3839
"@angular/compiler-cli": "11.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: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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+
24+
25+

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,10 +28,19 @@ 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';
35+
import {MatRadioModule} from '@angular/material/radio';
36+
import {MatCheckboxModule} from '@angular/material/checkbox';
37+
import {CreateCourseStep2Component} from './create-course/create-course-step-2/create-course-step-2.component';
38+
import {MatStepperModule} from '@angular/material/stepper';
39+
import { AddressFormComponent } from './address-form/address-form.component';
40+
import {CreateCourseStep3Component} from './create-course/create-course-step-3/create-course-step-3.component';
41+
import {CreateCourseStep1Component} from './create-course/create-course-step-1/create-course-step-1.component';
42+
import {FileUploadComponent} from './file-upload/file-upload.component';
43+
import {MatProgressBarModule} from '@angular/material/progress-bar';
3544

3645
@NgModule({
3746
declarations: [
@@ -42,7 +51,12 @@ import { CreateCourseComponent } from './create-course/create-course.component';
4251
CoursesCardListComponent,
4352
CourseDialogComponent,
4453
LoginComponent,
45-
CreateCourseComponent
54+
CreateCourseComponent,
55+
CreateCourseStep1Component,
56+
CreateCourseStep2Component,
57+
CreateCourseStep3Component,
58+
AddressFormComponent,
59+
FileUploadComponent
4660
],
4761
imports: [
4862
BrowserModule,
@@ -65,7 +79,11 @@ import { CreateCourseComponent } from './create-course/create-course.component';
6579
AppRoutingModule,
6680
MatSelectModule,
6781
MatDatepickerModule,
68-
MatMomentDateModule,
82+
MatNativeDateModule,
83+
MatRadioModule,
84+
MatCheckboxModule,
85+
MatStepperModule,
86+
MatProgressBarModule,
6987
FormsModule,
7088
ReactiveFormsModule
7189
],

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: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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+
ngOnInit() {
15+
16+
}
17+
18+
}

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: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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+
}

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

Lines changed: 0 additions & 10 deletions
This file was deleted.
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
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

6-
76
</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: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,40 @@
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'],
11+
providers: [{
12+
provide: STEPPER_GLOBAL_OPTIONS, useValue: {showError: true}
13+
}]
714
})
815
export class CreateCourseComponent implements OnInit {
916

10-
constructor() { }
1117

12-
ngOnInit(): void {
18+
constructor() {
19+
20+
}
21+
22+
23+
ngOnInit() {
24+
25+
26+
27+
}
28+
29+
30+
submit(step1, step2,step3) {
31+
32+
console.log("Step 1 form value", step1);
33+
34+
console.log("Step 2 form value", step2);
35+
36+
console.log("Step 3 form value", step3);
37+
1338
}
1439

1540
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
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+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import {Component, Input} from '@angular/core';
2+
import {HttpClient, HttpEventType} from '@angular/common/http';
3+
import {catchError, finalize} from 'rxjs/operators';
4+
import {AbstractControl, ControlValueAccessor, NG_VALIDATORS, NG_VALUE_ACCESSOR, Validator} from '@angular/forms';
5+
import {noop, of} from 'rxjs';
6+
7+
8+
@Component({
9+
selector: 'file-upload',
10+
templateUrl: "file-upload.component.html",
11+
styleUrls: ["file-upload.component.scss"]
12+
})
13+
export class FileUploadComponent {
14+
15+
16+
}

src/app/login/login.component.css

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@
1010
flex-direction: column;
1111
}
1212

13-
.form-val {
14-
margin-top: 10px;
15-
}
16-
1713
.test-input {
1814
border-bottom: 1px solid grey;
1915
margin-bottom: 10px;

0 commit comments

Comments
 (0)