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 { SaleCategoryDetailComponent } from './sale-category-detail.component';
|
||||
|
||||
@ -6,11 +6,13 @@ describe('SaleCategoryDetailComponent', () => {
|
||||
let component: SaleCategoryDetailComponent;
|
||||
let fixture: ComponentFixture<SaleCategoryDetailComponent>;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [SaleCategoryDetailComponent],
|
||||
}).compileComponents();
|
||||
}));
|
||||
beforeEach(
|
||||
waitForAsync(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [SaleCategoryDetailComponent],
|
||||
}).compileComponents();
|
||||
}),
|
||||
);
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(SaleCategoryDetailComponent);
|
||||
|
||||
@ -15,10 +15,10 @@ import { SaleCategoryService } from '../sale-category.service';
|
||||
styleUrls: ['./sale-category-detail.component.css'],
|
||||
})
|
||||
export class SaleCategoryDetailComponent implements OnInit, AfterViewInit {
|
||||
@ViewChild('nameElement', { static: true }) nameElement: ElementRef;
|
||||
@ViewChild('nameElement', { static: true }) nameElement?: ElementRef;
|
||||
form: FormGroup;
|
||||
taxes: Tax[];
|
||||
item: SaleCategory;
|
||||
taxes: Tax[] = [];
|
||||
item: SaleCategory = new SaleCategory();
|
||||
|
||||
constructor(
|
||||
private route: ActivatedRoute,
|
||||
@ -28,10 +28,7 @@ export class SaleCategoryDetailComponent implements OnInit, AfterViewInit {
|
||||
private toaster: ToasterService,
|
||||
private ser: SaleCategoryService,
|
||||
) {
|
||||
this.createForm();
|
||||
}
|
||||
|
||||
createForm() {
|
||||
// Create form
|
||||
this.form = this.fb.group({
|
||||
name: '',
|
||||
tax: '',
|
||||
@ -39,7 +36,8 @@ export class SaleCategoryDetailComponent implements OnInit, AfterViewInit {
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.route.data.subscribe((data: { item: SaleCategory; taxes: Tax[] }) => {
|
||||
this.route.data.subscribe((value) => {
|
||||
const data = value as { item: SaleCategory; taxes: Tax[] };
|
||||
this.showItem(data.item);
|
||||
this.taxes = data.taxes;
|
||||
});
|
||||
@ -55,7 +53,9 @@ export class SaleCategoryDetailComponent implements OnInit, AfterViewInit {
|
||||
|
||||
ngAfterViewInit() {
|
||||
setTimeout(() => {
|
||||
this.nameElement.nativeElement.focus();
|
||||
if (this.nameElement !== undefined) {
|
||||
this.nameElement.nativeElement.focus();
|
||||
}
|
||||
}, 0);
|
||||
}
|
||||
|
||||
@ -72,7 +72,7 @@ export class SaleCategoryDetailComponent 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('/sale-categories');
|
||||
|
||||
Reference in New Issue
Block a user