I have an array called rows of type TestEvent, and want to push to the array, i cant get to output the object i pushes it only shows undefined As you can see this.rows shows the arrays, but when i try to output a spesific array this.rows[0] i get undefined. (Typescript 2.7, Angular 5)
I've tried the following guides:
- http://robertdunawaypro.blogspot.no/2016/01/018-typescript-arrays-using-interface.html
- TypeScript push not available on interface array
- Typescript: push not available on custom typed array
import { TestEvent } from '../../models/event'
rows: TestEvent[] = []
public push(){
var test: TestEvent = {id: '222', category:'testcat', event_name: 'name'}
console.log(test) // Outputs the array
this.rows.push(test) //Push the array to this.rows
console.log(this.rows) //Outputs array of objects
consloe.log(this.rows[0]) //Outputs undefined
}
Event.ts
export interface TestEvent{
id?: string,
category?: string,
event_name?: string
}