Updated to angular 11
Now compiling with strict mode in typescript Need to error checking now
This commit is contained in:
@ -15,10 +15,10 @@ import { DeviceService } from '../device.service';
|
||||
styleUrls: ['./device-detail.component.css'],
|
||||
})
|
||||
export class DeviceDetailComponent implements OnInit, AfterViewInit {
|
||||
@ViewChild('nameElement', { static: true }) nameElement: ElementRef;
|
||||
@ViewChild('nameElement', { static: true }) nameElement?: ElementRef;
|
||||
form: FormGroup;
|
||||
sections: Section[];
|
||||
item: Device;
|
||||
sections: Section[] = [];
|
||||
item: Device = new Device();
|
||||
|
||||
constructor(
|
||||
private route: ActivatedRoute,
|
||||
@ -28,10 +28,7 @@ export class DeviceDetailComponent implements OnInit, AfterViewInit {
|
||||
private toaster: ToasterService,
|
||||
private ser: DeviceService,
|
||||
) {
|
||||
this.createForm();
|
||||
}
|
||||
|
||||
createForm() {
|
||||
// Create form
|
||||
this.form = this.fb.group({
|
||||
name: '',
|
||||
section: '',
|
||||
@ -40,7 +37,8 @@ export class DeviceDetailComponent implements OnInit, AfterViewInit {
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.route.data.subscribe((data: { item: Device; sections: Section[] }) => {
|
||||
this.route.data.subscribe((value) => {
|
||||
const data = value as { item: Device; sections: Section[] };
|
||||
this.showItem(data.item);
|
||||
this.sections = data.sections;
|
||||
});
|
||||
@ -57,7 +55,9 @@ export class DeviceDetailComponent implements OnInit, AfterViewInit {
|
||||
|
||||
ngAfterViewInit() {
|
||||
setTimeout(() => {
|
||||
this.nameElement.nativeElement.focus();
|
||||
if (this.nameElement !== undefined) {
|
||||
this.nameElement.nativeElement.focus();
|
||||
}
|
||||
}, 0);
|
||||
}
|
||||
|
||||
@ -74,7 +74,7 @@ export class DeviceDetailComponent 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('/devices');
|
||||
|
||||
Reference in New Issue
Block a user