Good afternoon, I have a problem when I want to return an array of objects from an external function.
I have declared an Object class with 2 properties, its constructor and one that works where I return an array with more than 50 objects for this example I only put 4 objects
export class Object { formcontrolName: String; formcontrolTraducido: String; constructor(formcontrolName: String, formcontrolTraducido: String) { this.formcontrolName = formcontrolName; this.formcontrolTraducido = formcontrolTraducido; } getData() { return [ { formcontrolName: 'callId', formcontrolTraducido: 'CId' }, { formcontrolName: 'collegeCareerId', formcontrolTraducido: 'Carrera' }, { formcontrolName: 'collegeDepartmentId', formcontrolTraducido: 'Nombre del Departamento/Centro', }, { formcontrolName: 'detailedAreaKnowledgeId', formcontrolTraducido: 'Campo Detallado', }, ]; } }
The problem is that I want to call from another component the getData function of the Object class, but when returning I get the following error:
Type '() => { formcontrolName: string; formcontrolTraducido: string; }[]' is missing the following properties from type 'Object[]': pop, push, concat, join
import { Component, OnInit } from '@angular/core'; import { Object } from './object'; @Component({ selector: 'my-app', templateUrl: './app.component.html', styleUrls: ['./app.component.css'], }) export class AppComponent implements OnInit { data: Object; arrayData: Object[]; constructor() {} ngOnInit() { this.arrayData = this.data.getData; console.log('arrayData: ' + this.arrayData); }
}
I am new to angular and to working with arrays, I would like to know what I can do to solve my problem. Thank you very much