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 { TaxDetailComponent } from './tax-detail.component';
|
||||
|
||||
@ -6,11 +6,13 @@ describe('TaxDetailComponent', () => {
|
||||
let component: TaxDetailComponent;
|
||||
let fixture: ComponentFixture<TaxDetailComponent>;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [TaxDetailComponent],
|
||||
}).compileComponents();
|
||||
}));
|
||||
beforeEach(
|
||||
waitForAsync(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [TaxDetailComponent],
|
||||
}).compileComponents();
|
||||
}),
|
||||
);
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(TaxDetailComponent);
|
||||
|
||||
@ -14,9 +14,9 @@ import { TaxService } from '../tax.service';
|
||||
styleUrls: ['./tax-detail.component.css'],
|
||||
})
|
||||
export class TaxDetailComponent implements OnInit, AfterViewInit {
|
||||
@ViewChild('nameElement', { static: true }) nameElement: ElementRef;
|
||||
@ViewChild('nameElement', { static: true }) nameElement?: ElementRef;
|
||||
form: FormGroup;
|
||||
item: Tax;
|
||||
item: Tax = new Tax();
|
||||
|
||||
constructor(
|
||||
private route: ActivatedRoute,
|
||||
@ -26,10 +26,7 @@ export class TaxDetailComponent implements OnInit, AfterViewInit {
|
||||
private toaster: ToasterService,
|
||||
private ser: TaxService,
|
||||
) {
|
||||
this.createForm();
|
||||
}
|
||||
|
||||
createForm() {
|
||||
// Create form
|
||||
this.form = this.fb.group({
|
||||
name: '',
|
||||
rate: '',
|
||||
@ -37,7 +34,8 @@ export class TaxDetailComponent implements OnInit, AfterViewInit {
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.route.data.subscribe((data: { item: Tax }) => {
|
||||
this.route.data.subscribe((value) => {
|
||||
const data = value as { item: Tax };
|
||||
this.showItem(data.item);
|
||||
});
|
||||
}
|
||||
@ -52,7 +50,9 @@ export class TaxDetailComponent implements OnInit, AfterViewInit {
|
||||
|
||||
ngAfterViewInit() {
|
||||
setTimeout(() => {
|
||||
this.nameElement.nativeElement.focus();
|
||||
if (this.nameElement !== undefined) {
|
||||
this.nameElement.nativeElement.focus();
|
||||
}
|
||||
}, 0);
|
||||
}
|
||||
|
||||
@ -69,7 +69,7 @@ export class TaxDetailComponent 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('/taxes');
|
||||
|
||||
@ -11,15 +11,16 @@ import { TaxListDataSource } from './tax-list-datasource';
|
||||
styleUrls: ['./tax-list.component.css'],
|
||||
})
|
||||
export class TaxListComponent implements OnInit {
|
||||
dataSource: TaxListDataSource;
|
||||
list: Tax[];
|
||||
list: Tax[] = [];
|
||||
dataSource: TaxListDataSource = new TaxListDataSource(this.list);
|
||||
/** Columns displayed in the table. Columns IDs can be added, removed, or reordered. */
|
||||
displayedColumns = ['name', 'rate', 'isFixture'];
|
||||
|
||||
constructor(private route: ActivatedRoute) {}
|
||||
|
||||
ngOnInit() {
|
||||
this.route.data.subscribe((data: { list: Tax[] }) => {
|
||||
this.route.data.subscribe((value) => {
|
||||
const data = value as { list: Tax[] };
|
||||
this.list = data.list;
|
||||
});
|
||||
this.dataSource = new TaxListDataSource(this.list);
|
||||
|
||||
@ -18,7 +18,7 @@ const serviceName = 'TaxService';
|
||||
export class TaxService {
|
||||
constructor(private http: HttpClient, private log: ErrorLoggerService) {}
|
||||
|
||||
get(id: string): Observable<Tax> {
|
||||
get(id: string | null): Observable<Tax> {
|
||||
const getUrl: string = id === null ? url : `${url}/${id}`;
|
||||
return <Observable<Tax>>(
|
||||
this.http.get<Tax>(getUrl).pipe(catchError(this.log.handleError(serviceName, `get id=${id}`)))
|
||||
|
||||
Reference in New Issue
Block a user