从Angular 2 Beta 12升级到RC 1 - 编译问题

时间:2016-05-04 14:00:57

标签: angular angular2-services

所以我正在进行从Angular 2.0.0-beta.12到RC 1(2.0.0-rc.1)的繁琐更新,我的应用程序已经有所破解。我修复了许多错误,但由于以下原因,我似乎无法编译:

    app/components/Projects/list/ProjectListComponent.ts(33,22): error TS2339: Property 'subscribe' does not exist on type 'Object'.

    app/services/projects-main.ts(33,9): error TS2322: Type 'Observable<{}>' is not assignable to type 'Observable<IProjectsMain[]>'.
      Type '{}' is not assignable to type 'IProjectsMain[]'.
        Property 'length' is missing in type '{}'.


    app/services/projects-main.ts(42,29): error TS2339: Property 'project' does not exist on type '{ projects: IProjectsMain[]; }'.

我很难过,因为我对Angular相对较新,但我无法在网上找到有关为什么会突然中断的原因。

我的文件如下:

- app / components / Projects / list / ProjectListComponent.ts

        import {Component, ElementRef, OnInit} from '@angular/core';
        import {ProjectsMainApi} from "../../../services/projects-main";
        declare var jQuery: any;
        declare var subscribe: any;


        import { ROUTER_DIRECTIVES } from '@angular/router-deprecated';

        @Component({
            selector: 'projects',
            templateUrl: './app/components/Projects/list/index.html',
            directives: [ROUTER_DIRECTIVES]
        })

        export class ProjectsListComponent implements OnInit {

            elementRef: ElementRef;

            project: Object;

            constructor(elementRef: ElementRef, private _projectsmainapi: ProjectsMainApi) {
                this.elementRef = elementRef;
                this.project = this._projectsmainapi.project$;

                this._projectsmainapi.getProjectsMain();        
            }
            ngOnInit() {
                this.project.subscribe(() => {
                    //when the data is feed to the page the subscribe will fire and activate my plugin
                   // for demo here it is a simple alert
                   alert('API ACTIVATED');
                    console.log('Projects Initialized')          
                });

            }
        }

- 应用程序/服务/项目-main.ts

        import {Http, Headers, Response} from "@angular/http"
        import {Injectable} from "@angular/core"
        import {IProjectsMain} from "../interfaces/IProjectsMain"
        import 'rxjs/Rx';
        import {Observable} from 'rxjs/Observable';
        import {Observer} from 'rxjs/Observer';
        import 'rxjs/add/operator/share';
        import 'rxjs/add/operator/map';

        @Injectable()
        export class ProjectsMainApi {

            apiUrl: string = "http://www.testside.io/api/projects";

            headers: Headers = new Headers;

            project$: Observable<IProjectsMain[]>;

            private _ProjectsMainObserver: Observer<IProjectsMain[]>;

            private _dataStore: {

                projects: IProjectsMain[]

            };

            constructor(private _http: Http) {

                this.headers.append('Content-Type', 'application/x-www-form-urlencoded');

                this.headers.append('X-Requested-With', 'XMLHttpRequest');

                this.project$ = new Observable(observer => this._ProjectsMainObserver = observer).share();

                this._dataStore = { projects: [] };
            }

            public getProjectsMain() {

                this._http.get(this.apiUrl).map(response => response.json()).subscribe(data => {

                    this._dataStore.project = data.project;

                    this._ProjectsMainObserver.next(this._dataStore.project);

                }, error => console.log('Could not load projects.'),
                    () => "doneskies");

            }

        }

- 应用程序/接口/ IProjectsMain.ts

    export interface IProjectsMain {
        id?: number;
        title: string;
        slug: string;
        backgroundone: string;
        foregroundone: string;
        backgroundtwo: string;
        foregroundtwo: string;  
    }

0 个答案:

没有答案