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 { PrinterDetailComponent } from './printer-detail.component';
|
||||
|
||||
@ -6,11 +6,13 @@ describe('PrinterDetailComponent', () => {
|
||||
let component: PrinterDetailComponent;
|
||||
let fixture: ComponentFixture<PrinterDetailComponent>;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [PrinterDetailComponent],
|
||||
}).compileComponents();
|
||||
}));
|
||||
beforeEach(
|
||||
waitForAsync(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [PrinterDetailComponent],
|
||||
}).compileComponents();
|
||||
}),
|
||||
);
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(PrinterDetailComponent);
|
||||
|
||||
@ -14,9 +14,9 @@ import { PrinterService } from '../printer.service';
|
||||
styleUrls: ['./printer-detail.component.css'],
|
||||
})
|
||||
export class PrinterDetailComponent implements OnInit, AfterViewInit {
|
||||
@ViewChild('nameElement', { static: true }) nameElement: ElementRef;
|
||||
@ViewChild('nameElement', { static: true }) nameElement?: ElementRef;
|
||||
form: FormGroup;
|
||||
item: Printer;
|
||||
item: Printer = new Printer();
|
||||
|
||||
constructor(
|
||||
private route: ActivatedRoute,
|
||||
@ -26,10 +26,7 @@ export class PrinterDetailComponent implements OnInit, AfterViewInit {
|
||||
private toaster: ToasterService,
|
||||
private ser: PrinterService,
|
||||
) {
|
||||
this.createForm();
|
||||
}
|
||||
|
||||
createForm() {
|
||||
// Create form
|
||||
this.form = this.fb.group({
|
||||
name: '',
|
||||
address: '',
|
||||
@ -38,7 +35,8 @@ export class PrinterDetailComponent implements OnInit, AfterViewInit {
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.route.data.subscribe((data: { item: Printer }) => {
|
||||
this.route.data.subscribe((value) => {
|
||||
const data = value as { item: Printer };
|
||||
this.showItem(data.item);
|
||||
});
|
||||
}
|
||||
@ -54,7 +52,9 @@ export class PrinterDetailComponent implements OnInit, AfterViewInit {
|
||||
|
||||
ngAfterViewInit() {
|
||||
setTimeout(() => {
|
||||
this.nameElement.nativeElement.focus();
|
||||
if (this.nameElement !== undefined) {
|
||||
this.nameElement.nativeElement.focus();
|
||||
}
|
||||
}, 0);
|
||||
}
|
||||
|
||||
@ -71,7 +71,7 @@ export class PrinterDetailComponent implements OnInit, AfterViewInit {
|
||||
}
|
||||
|
||||
delete() {
|
||||
this.ser.delete(this.item.id).subscribe(
|
||||
this.ser.delete(this.item.id as string).subscribe(
|
||||
() => {
|
||||
this.toaster.show('Success', '');
|
||||
this.router.navigateByUrl('/printers');
|
||||
|
||||
@ -11,15 +11,16 @@ import { PrinterListDataSource } from './printer-list-datasource';
|
||||
styleUrls: ['./printer-list.component.css'],
|
||||
})
|
||||
export class PrinterListComponent implements OnInit {
|
||||
dataSource: PrinterListDataSource;
|
||||
list: Printer[];
|
||||
list: Printer[] = [];
|
||||
dataSource: PrinterListDataSource = new PrinterListDataSource(this.list);
|
||||
/** Columns displayed in the table. Columns IDs can be added, removed, or reordered. */
|
||||
displayedColumns = ['name', 'address', 'cutCode'];
|
||||
|
||||
constructor(private route: ActivatedRoute) {}
|
||||
|
||||
ngOnInit() {
|
||||
this.route.data.subscribe((data: { list: Printer[] }) => {
|
||||
this.route.data.subscribe((value) => {
|
||||
const data = value as { list: Printer[] };
|
||||
this.list = data.list;
|
||||
});
|
||||
this.dataSource = new PrinterListDataSource(this.list);
|
||||
|
||||
@ -18,7 +18,7 @@ const serviceName = 'PrinterService';
|
||||
export class PrinterService {
|
||||
constructor(private http: HttpClient, private log: ErrorLoggerService) {}
|
||||
|
||||
get(id: string): Observable<Printer> {
|
||||
get(id: string | null): Observable<Printer> {
|
||||
const getUrl: string = id === null ? url : `${url}/${id}`;
|
||||
return <Observable<Printer>>(
|
||||
this.http
|
||||
|
||||
Reference in New Issue
Block a user