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