Skip to content

Commit ecddea6

Browse files
author
Your Name
committed
Angular Forms In Depth
1 parent f0a2943 commit ecddea6

File tree

4 files changed

+36
-4
lines changed

4 files changed

+36
-4
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
2+
3+
<div [formGroup]="form">
4+
5+
<mat-radio-group formControlName="courseType">
6+
7+
<mat-radio-button value="free">Free</mat-radio-button>
8+
9+
<mat-radio-button value="premium">Premium</mat-radio-button>
10+
11+
</mat-radio-group>
12+
13+
14+
</div>
15+
16+
<div class="form-val">
17+
18+
{{form.value | json}}
19+
20+
</div>

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ import {FormBuilder, FormGroup, Validators} from '@angular/forms';
99
})
1010
export class CreateCourseStep2Component implements OnInit {
1111

12+
form = this.fb.group({
13+
courseType: ['premium', Validators.required]
14+
});
15+
16+
constructor(private fb: FormBuilder) {
17+
18+
}
1219

1320
ngOnInit() {
1421

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33

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

6-
<mat-horizontal-stepper [linear]="true"
6+
<mat-horizontal-stepper [linear]="false"
77
class="mat-elevation-z5" labelPosition="bottom">
88

9-
<mat-step [stepControl]="step1.form">
9+
<mat-step [stepControl]="step1.form" errorMessage="Landing page in error">
1010

1111
<ng-template matStepLabel>course landing page details</ng-template>
1212

@@ -21,7 +21,7 @@ <h2 class="title">Create New Course</h2>
2121
</mat-step>
2222

2323

24-
<mat-step>
24+
<mat-step errorMessage="Pricing in error">
2525

2626
<create-course-step-2></create-course-step-2>
2727

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@ import {STEPPER_GLOBAL_OPTIONS} from '@angular/cdk/stepper';
77
@Component({
88
selector: 'create-course',
99
templateUrl: './create-course.component.html',
10-
styleUrls: ['./create-course.component.scss']
10+
styleUrls: ['./create-course.component.scss'],
11+
providers: [
12+
{
13+
provide: STEPPER_GLOBAL_OPTIONS, useValue: {showError:true}
14+
}
15+
]
1116
})
1217
export class CreateCourseComponent implements OnInit {
1318

0 commit comments

Comments
 (0)