I am trying to get an array out of a different class but he says the function does not exist. here is my code:
courses.component.ts:
import {Component} from 'angular2/core'
import {CourseService} from './course.service'
@Component({
selector: 'courses',
template: `
<h2>Courses</h2>
{{ title }}
<ul>
<li *ngFor ="#course of courses">
{{course}}
</li>
</ul>
`,
providers: [CourseService]
})
export class CoursesComponent{
title = "The title of courses page";
courses;
constructor(courseService: CourseService){
this.courses = CourseService.getCourses();
}
}
course.service.ts:
export class CourseService{
getCourses() : string[]{
return ["Course1","Course2","Course3"];
}
}
You need to reference the argument name, not the argument type
this.courses = courseService.getCourses();
^ lower case c
I think it's some kind of bug, because TypeScript recognize me the method but when I delete and type the method again getCourses() in the component, it says that the method is not found, then I go to the Service and start to delete blank lines, and the method Works. I'm currently using Angular 4
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With