如何解决无法解决角度上的所有参数错误

用户6852826

刚开始使用 angular 2,遇到了我的第一个错误。我正在尝试创建用于从服务器获取数据的服务,但出现此错误

错误:无法解析 CourseService 的所有参数:(?)。在 SyntaxError.ZoneAwareError (http:……}

这是抛出错误 app/courses/courses.service.ts 的服务代码

import { Http } from '@angular/http';

export class CourseService {

    private  _courses : Object[];

    public get courses() : Object[] {
        return this._courses;
    }

    public set courses(v : Object[]) {
        this._courses = v;
    }

    constructor(private http: Http) {
        http.get("https://jsonplaceholder.typicode.com/posts").subscribe(data => {
            this._courses = data.json();
        });
    }
}

此服务应该在 app/courses/courses.component.ts 中使用

import { Component } from '@angular/core'
import { CourseService } from "app/courses/course.service";

@Component({
    selector: 'courses',
    providers: [CourseService],
    templateUrl: './courses.component.html',
    styleUrls: ['./courses.component.css'] 
})

export class CoursesComponent {
    title : string = "The title of the Course";
    courses : Object[];

    constructor(private courseService: CourseService) {
        console.log("hello");
        this.courses = courseService.courses;
    }
}

和 app.module 包含

....
....
import { AppComponent } from './app.component';
import { CoursesComponent }  from './courses/courses.component';
import { CourseService } from "./courses/course.service";

@NgModule({
     declarations: [
       AppComponent,
       CoursesComponent,
    ],
    imports: [
      BrowserModule,
      FormsModule,
      HttpModule
    ],
    providers: [CourseService],
    bootstrap: [AppComponent, CoursesComponent]
})
 export class AppModule { }
Zhang Bruce

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

ionic2-无法解决所有参数错误

角度如何解决无限递归?

我该如何解决无法在Nuxt中对函数错误进行字符串化处理?

如何解决无法加载此类文件openssl错误?

如何解决无法读取空错误的属性“值”?

如何解决无法散列的类型:“列表”错误

我该如何解决无法获取/错误的nodejs

如何解决无法停止:杀死VM MobyLinuxVM没有停止泊坞窗上的错误

如何解决无法合并dex

如何解决 NotificationType 类中的角度构建失败“Angular2-Notification”参数错误?

如何解决json的多于1个参数错误?

如何解决无法解决的方法'put(int,int)'错误

如何解决无法解决XSSFWorkbook类的问题?

如何解决无法解决对gitlab的依赖

如何解决“方程式可能无法解决所有“解决”变量的问题”错误

如何解决无法使用react typescript来使“ xx”键入固有属性和道具的错误?

如何解决聚合函数错误?

如何解决无法将类型...的值转换为预期的参数类型inout _

如何解决无法转换“字符串”类型的值?到预期的参数类型“ URL”

如何解决无参数重新分配

如何解决无法将字符串转换为浮点错误

如何解决无法初始化设备hci0。错误?

如何解决无法连接“ str”和“ file”对象的错误?

如何解决无法调用“ DataFrame”对象的计算错误

如何解决无法读取 React js 中未定义错误的属性“map”?

如何解决无法读取未定义错误的属性“ timepicker”

如何解决无法发送请求的邮递员这个错误?

如何解决无卡开发者密钥错误

我该如何解决无法观看文件的问题