Skip to content

Commit

Permalink
Use checkbox for error
Browse files Browse the repository at this point in the history
  • Loading branch information
fboeller committed Mar 6, 2021
1 parent bca1587 commit 4b0fd1a
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 6 deletions.
8 changes: 8 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"@angular/common": "~11.2.0",
"@angular/compiler": "~11.2.0",
"@angular/core": "~11.2.0",
"@angular/forms": "^11.2.4",
"@angular/platform-browser": "^11.2.3",
"@angular/platform-browser-dynamic": "^11.2.3",
"@ngrx/effects": "^11.0.1",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
<button (click)="load(42, false)">Load</button>
<button (click)="load(42, true)">Load with error</button>
<form [formGroup]="form">
<label for="isError">If the load should result in an error</label>
<input type="checkbox" name="isError" formControlName="isError" required />
<button (click)="load(42)">Load</button>
</form>
11 changes: 8 additions & 3 deletions projects/example-app/src/app/load-form/load-form.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Loadable } from 'projects/ngx-loadable/src/public-api';
import { Subject } from 'rxjs';
import { switchMap } from 'rxjs/operators';
import { LoadService } from '../load.service';
import { FormBuilder } from '@angular/forms';

@Component({
selector: 'app-load-form',
Expand All @@ -15,7 +16,11 @@ export class LoadFormComponent {

load$ = new Subject<{ id: number; error: boolean }>();

constructor(private loadService: LoadService) {
form = this.fb.group({
isError: [false],
});

constructor(private loadService: LoadService, private fb: FormBuilder) {
this.load$
.pipe(
switchMap(({ id, error }) =>
Expand All @@ -25,7 +30,7 @@ export class LoadFormComponent {
.subscribe(this.loadable);
}

load(id: number, error: boolean): void {
this.load$.next({ id, error });
load(id: number): void {
this.load$.next({ id, error: this.form.value.isError });
}
}
3 changes: 2 additions & 1 deletion projects/example-app/src/app/load-form/load-form.module.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { LoadFormComponent } from './load-form.component';
import { ReactiveFormsModule } from '@angular/forms';

@NgModule({
imports: [CommonModule],
imports: [CommonModule, ReactiveFormsModule],
declarations: [LoadFormComponent],
exports: [LoadFormComponent],
})
Expand Down

0 comments on commit 4b0fd1a

Please sign in to comment.