I am facing an issue with defining a value for students in TypeScript. It is giving me an error saying that it can't be used as index type. Just to clarify, I have declared id as number (not Number) and Name as string (not String).
import { Component } from '@angular/core';
interface student {
Id: number;
Name: string;
}
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css'],
})
export class AppComponent {
students: Array<student> = [];
color: string = 'color: red';
color2: string = 'color : blue';
userName: string = '';
title = 'ng-project';
constructor() {
this.students[{ Id: 0, Name: 'John' }];
}
}