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 { MenuCategoryDetailComponent } from './menu-category-detail.component';
|
||||
|
||||
@ -6,11 +6,13 @@ describe('MenuCategoryDetailComponent', () => {
|
||||
let component: MenuCategoryDetailComponent;
|
||||
let fixture: ComponentFixture<MenuCategoryDetailComponent>;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [MenuCategoryDetailComponent],
|
||||
}).compileComponents();
|
||||
}));
|
||||
beforeEach(
|
||||
waitForAsync(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [MenuCategoryDetailComponent],
|
||||
}).compileComponents();
|
||||
}),
|
||||
);
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(MenuCategoryDetailComponent);
|
||||
|
||||
@ -14,9 +14,9 @@ import { MenuCategoryService } from '../menu-category.service';
|
||||
styleUrls: ['./menu-category-detail.component.css'],
|
||||
})
|
||||
export class MenuCategoryDetailComponent implements OnInit, AfterViewInit {
|
||||
@ViewChild('nameElement', { static: true }) nameElement: ElementRef;
|
||||
@ViewChild('nameElement', { static: true }) nameElement?: ElementRef;
|
||||
form: FormGroup;
|
||||
item: MenuCategory;
|
||||
item: MenuCategory = new MenuCategory();
|
||||
|
||||
constructor(
|
||||
private route: ActivatedRoute,
|
||||
@ -26,10 +26,7 @@ export class MenuCategoryDetailComponent implements OnInit, AfterViewInit {
|
||||
private toaster: ToasterService,
|
||||
private ser: MenuCategoryService,
|
||||
) {
|
||||
this.createForm();
|
||||
}
|
||||
|
||||
createForm() {
|
||||
// Create form
|
||||
this.form = this.fb.group({
|
||||
name: '',
|
||||
discountLimit: '',
|
||||
@ -38,7 +35,8 @@ export class MenuCategoryDetailComponent implements OnInit, AfterViewInit {
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.route.data.subscribe((data: { item: MenuCategory }) => {
|
||||
this.route.data.subscribe((value) => {
|
||||
const data = value as { item: MenuCategory };
|
||||
this.showItem(data.item);
|
||||
});
|
||||
}
|
||||
@ -54,7 +52,9 @@ export class MenuCategoryDetailComponent implements OnInit, AfterViewInit {
|
||||
|
||||
ngAfterViewInit() {
|
||||
setTimeout(() => {
|
||||
this.nameElement.nativeElement.focus();
|
||||
if (this.nameElement !== undefined) {
|
||||
this.nameElement.nativeElement.focus();
|
||||
}
|
||||
}, 0);
|
||||
}
|
||||
|
||||
@ -71,7 +71,7 @@ export class MenuCategoryDetailComponent 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('/menu-categories');
|
||||
|
||||
@ -5,7 +5,7 @@ import { tap } from 'rxjs/operators';
|
||||
import { MenuCategory } from '../../core/menu-category';
|
||||
|
||||
export class MenuCategoryListDatasource extends DataSource<MenuCategory> {
|
||||
private data: MenuCategory[];
|
||||
private data: MenuCategory[] = [];
|
||||
|
||||
constructor(private readonly dataObs: Observable<MenuCategory[]>) {
|
||||
super();
|
||||
|
||||
@ -16,10 +16,10 @@ import { MenuCategoryListDatasource } from './menu-category-list-datasource';
|
||||
styleUrls: ['./menu-category-list.component.css'],
|
||||
})
|
||||
export class MenuCategoryListComponent implements OnInit {
|
||||
@ViewChild('table', { static: true }) table: MatTable<MenuCategory>;
|
||||
dataSource: MenuCategoryListDatasource;
|
||||
list: MenuCategory[];
|
||||
data: BehaviorSubject<MenuCategory[]>;
|
||||
@ViewChild('table', { static: true }) table?: MatTable<MenuCategory>;
|
||||
list: MenuCategory[] = [];
|
||||
data: BehaviorSubject<MenuCategory[]> = new BehaviorSubject<MenuCategory[]>(this.list);
|
||||
dataSource: MenuCategoryListDatasource = new MenuCategoryListDatasource(this.data);
|
||||
/** Columns displayed in the table. Columns IDs can be added, removed, or reordered. */
|
||||
displayedColumns = ['name', 'discountLimit', 'isActive', 'isFixture'];
|
||||
|
||||
@ -29,14 +29,14 @@ export class MenuCategoryListComponent implements OnInit {
|
||||
private toaster: ToasterService,
|
||||
private ser: MenuCategoryService,
|
||||
) {
|
||||
this.data = new BehaviorSubject([]);
|
||||
this.data.subscribe((data: MenuCategory[]) => {
|
||||
this.list = data;
|
||||
});
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.route.data.subscribe((data: { list: MenuCategory[] }) => {
|
||||
this.route.data.subscribe((value) => {
|
||||
const data = value as { list: MenuCategory[] };
|
||||
data.list.forEach((x) => {
|
||||
x.discountLimit /= 100;
|
||||
});
|
||||
|
||||
@ -18,7 +18,7 @@ const serviceName = 'MenuCategoryService';
|
||||
export class MenuCategoryService {
|
||||
constructor(private http: HttpClient, private log: ErrorLoggerService) {}
|
||||
|
||||
get(id: string): Observable<MenuCategory> {
|
||||
get(id: string | null): Observable<MenuCategory> {
|
||||
const getUrl: string = id === null ? url : `${url}/${id}`;
|
||||
return <Observable<MenuCategory>>(
|
||||
this.http
|
||||
|
||||
Reference in New Issue
Block a user