Updated to angular 11
Now compiling with strict mode in typescript Need to error checking now
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
|
||||
|
||||
import { SectionPrinterComponent } from './section-printer.component';
|
||||
|
||||
@ -6,11 +6,13 @@ describe('SectionPrinterComponent', () => {
|
||||
let component: SectionPrinterComponent;
|
||||
let fixture: ComponentFixture<SectionPrinterComponent>;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [SectionPrinterComponent],
|
||||
}).compileComponents();
|
||||
}));
|
||||
beforeEach(
|
||||
waitForAsync(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [SectionPrinterComponent],
|
||||
}).compileComponents();
|
||||
}),
|
||||
);
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(SectionPrinterComponent);
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import { Component, ElementRef, OnInit, ViewChild } from '@angular/core';
|
||||
import { FormArray, FormBuilder, FormGroup } from '@angular/forms';
|
||||
import { AbstractControl, FormArray, FormBuilder, FormGroup } from '@angular/forms';
|
||||
import { MatDialog } from '@angular/material/dialog';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
import { BehaviorSubject } from 'rxjs';
|
||||
@ -20,14 +20,14 @@ import { SectionPrinterService } from './section-printer.service';
|
||||
styleUrls: ['./section-printer.component.css'],
|
||||
})
|
||||
export class SectionPrinterComponent implements OnInit {
|
||||
@ViewChild('section', { static: true }) sectionElement: ElementRef;
|
||||
@ViewChild('section', { static: true }) sectionElement?: ElementRef;
|
||||
form: FormGroup;
|
||||
dataSource: SectionPrinterDataSource;
|
||||
public listObservable = new BehaviorSubject<SectionPrinter[]>([]);
|
||||
list: SectionPrinter[];
|
||||
sections: Section[];
|
||||
printers: Printer[];
|
||||
sectionId: string;
|
||||
dataSource: SectionPrinterDataSource = new SectionPrinterDataSource(this.listObservable);
|
||||
list: SectionPrinter[] = [];
|
||||
sections: Section[] = [];
|
||||
printers: Printer[] = [];
|
||||
sectionId = '';
|
||||
displayedColumns = ['menuCategory', 'printer', 'copies'];
|
||||
|
||||
constructor(
|
||||
@ -38,34 +38,30 @@ export class SectionPrinterComponent implements OnInit {
|
||||
private dialog: MatDialog,
|
||||
private ser: SectionPrinterService,
|
||||
) {
|
||||
this.createForm();
|
||||
// Create form
|
||||
this.form = this.fb.group({
|
||||
section: '',
|
||||
menuCategories: this.fb.array([]),
|
||||
});
|
||||
route.params.pipe(map((p) => p.id)).subscribe((x) => {
|
||||
this.sectionId = x;
|
||||
});
|
||||
}
|
||||
|
||||
createForm() {
|
||||
this.form = this.fb.group({
|
||||
section: '',
|
||||
menuCategories: this.fb.array([]),
|
||||
});
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.route.data.subscribe(
|
||||
(data: { list: SectionPrinter[]; sections: Section[]; printers: Printer[] }) => {
|
||||
this.sections = data.sections;
|
||||
this.printers = data.printers;
|
||||
this.showItem(data.list);
|
||||
this.dataSource = new SectionPrinterDataSource(this.listObservable);
|
||||
this.listObservable.next(this.list);
|
||||
},
|
||||
);
|
||||
this.route.data.subscribe((value) => {
|
||||
const data = value as { list: SectionPrinter[]; sections: Section[]; printers: Printer[] };
|
||||
this.sections = data.sections;
|
||||
this.printers = data.printers;
|
||||
this.showItem(data.list);
|
||||
this.dataSource = new SectionPrinterDataSource(this.listObservable);
|
||||
this.listObservable.next(this.list);
|
||||
});
|
||||
}
|
||||
|
||||
showItem(list: SectionPrinter[]) {
|
||||
this.list = list;
|
||||
this.form.get('section').setValue(this.sectionId);
|
||||
(this.form.get('section') as AbstractControl).setValue(this.sectionId);
|
||||
this.form.setControl(
|
||||
'menuCategories',
|
||||
this.fb.array(
|
||||
|
||||
@ -18,7 +18,7 @@ const serviceName = 'SectionPrinterService';
|
||||
export class SectionPrinterService {
|
||||
constructor(private http: HttpClient, private log: ErrorLoggerService) {}
|
||||
|
||||
get(id: string): Observable<SectionPrinter[]> {
|
||||
get(id: string | null): Observable<SectionPrinter[]> {
|
||||
const getUrl: string = id === null ? `${url}` : `${url}/${id}`;
|
||||
return <Observable<SectionPrinter[]>>(
|
||||
this.http
|
||||
|
||||
Reference in New Issue
Block a user