我试图从另一个类中获取一个数组,但他说该函数不存在。
这是我的代码:
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"];
}
}
最佳答案
您需要引用参数名称,而不是参数类型
this.courses = courseService.getCourses();
^ lower case c
关于angular - Angular 2 : is not a function but it exist,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/40708944/