I'm starting with angular4 , using the angular-cli
tool I generated a test project and I have a problem when I try to use the imported service method, this would be the source code:
app / student.service.ts
import { Injectable } from '@angular/core';
@Injectable()
export class EstudianteService {
constructor() { }
listar():string[] {
return ["neder", "alfonso", "fandiño", "andrade"];
}
}
app / student / student.component.ts
import { Component /* [, mas elementos...] */} from '@angular/core';
import { EstudianteService } from '../estudiante.service';
@Component({
selector: 'app-estudiante',
templateUrl: './estudiante.component.html',
styleUrls: ['./estudiante.component.css'],
providers: [EstudianteService]
})
export class EstudianteComponent implements OnInit {
lista:string[];
/* Definiciones... */
constructor(estudiante: EstudianteService) {
this.lista = estudiante.listar();
}
/* mas implementación... */
}
I am getting the following error in the console, I have not been able to determine exactly where the problem is.
I have been using angle 2 guiás based on its similar aspects and because more information abounds such as:
They could advise me a little with this, the truth I am studying from today I have seemed very Bacano all the subject of "divide and conquer" for this version but I got stuck at this point.
I tried to indicate the scope of the method as public
public listar():string[] {
return ["neder", "alfonso", "fandiño", "andrade"];
}
Or at the time of calling, I have even used the term this
to resemble the examples proposed in the pages of differentiated above, although I'm almost sure that has nothing to do
constructor(public estudiante: EstudianteService) {
this.lista = this.estudiante.listar();
}
I already appreciate the collaboration offered.