I am completely new to both Angular and TypeScript, so I'd like to start by mentioning that.
In my Angular program, I have implemented routing to display more information on a separate page.
The errors are occurring within the ngOnInit() method:
The first error is related to: this.blomId TS2322: Type 'string | null' is not assignable to type 'number'. Type 'null' is not assignable to type 'number'.
The second error is related to: data[this.blomId] TS7053: Element implicitly has an 'any' type because expression of type 'number' cannot be used to index type 'Object'. No index signature with a parameter of type 'number' was found on type 'Object'.
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { BlommorService } from '../blommor.service';
@Component({
selector: 'app-info',
templateUrl: './info.component.html',
styleUrls: ['./info.component.scss']
})
export class InfoComponent implements OnInit {
blomId: number;
valdblomma: any;
constructor(private activatedRoute: ActivatedRoute, private blomservice: BlommorService) {this.blomId = 0;}
ngOnInit() {
this.blomId = this.activatedRoute.snapshot.paramMap.get('id');
this.blomservice.getBlommor().subscribe((data) => {
this.valdblomma = data[this.blomId];
});
}
}
Any assistance would be greatly appreciated.