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');
|
||||
|
||||
@ -5,7 +5,7 @@ import { tap } from 'rxjs/operators';
|
||||
import { SaleCategory } from '../../core/sale-category';
|
||||
|
||||
export class SaleCategoryListDatasource extends DataSource<SaleCategory> {
|
||||
private data: SaleCategory[];
|
||||
private data: SaleCategory[] = [];
|
||||
|
||||
constructor(private readonly dataObs: Observable<SaleCategory[]>) {
|
||||
super();
|
||||
|
||||
@ -15,10 +15,10 @@ import { SaleCategoryListDatasource } from './sale-category-list-datasource';
|
||||
styleUrls: ['./sale-category-list.component.css'],
|
||||
})
|
||||
export class SaleCategoryListComponent implements OnInit {
|
||||
@ViewChild('table', { static: true }) table: MatTable<SaleCategory>;
|
||||
dataSource: SaleCategoryListDatasource;
|
||||
list: SaleCategory[];
|
||||
data: BehaviorSubject<SaleCategory[]>;
|
||||
@ViewChild('table', { static: true }) table?: MatTable<SaleCategory>;
|
||||
data: BehaviorSubject<SaleCategory[]> = new BehaviorSubject<SaleCategory[]>([]);
|
||||
dataSource: SaleCategoryListDatasource = new SaleCategoryListDatasource(this.data);
|
||||
list: SaleCategory[] = [];
|
||||
/** Columns displayed in the table. Columns IDs can be added, removed, or reordered. */
|
||||
displayedColumns = ['name', 'tax'];
|
||||
|
||||
@ -28,14 +28,14 @@ export class SaleCategoryListComponent implements OnInit {
|
||||
private toaster: ToasterService,
|
||||
private ser: SaleCategoryService,
|
||||
) {
|
||||
this.data = new BehaviorSubject([]);
|
||||
this.data.subscribe((data: SaleCategory[]) => {
|
||||
this.list = data;
|
||||
});
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.route.data.subscribe((data: { list: SaleCategory[] }) => {
|
||||
this.route.data.subscribe((value) => {
|
||||
const data = value as { list: SaleCategory[] };
|
||||
this.data.next(data.list);
|
||||
});
|
||||
this.dataSource = new SaleCategoryListDatasource(this.data);
|
||||
|
||||
@ -18,7 +18,7 @@ const serviceName = 'SaleCategoryService';
|
||||
export class SaleCategoryService {
|
||||
constructor(private http: HttpClient, private log: ErrorLoggerService) {}
|
||||
|
||||
get(id: string): Observable<SaleCategory> {
|
||||
get(id: string | null): Observable<SaleCategory> {
|
||||
const getUrl: string = id === null ? url : `${url}/${id}`;
|
||||
return <Observable<SaleCategory>>(
|
||||
this.http
|
||||
|
||||
Reference in New Issue
Block a user