angular2 gulp task is compiling but with errors

2019-09-10 11:45发布

问题:

I am working on a gulpfile where I want to compile the angular 2 app but I get some errors:

What do they mean by it does not exist on type "..." and how do I make it exist? Where nativeWindow is a window.service.ts looks like this:

//--------------------------------------------------------------------------------------------------
// Imports Section:
//--------------------------------------------------------------------------------------------------
import {Injectable} from 'angular2/core'
import {window} from 'angular2/src/facade/browser';

//--------------------------------------------------------------------------------------------------
// Service Class:
//--------------------------------------------------------------------------------------------------
@Injectable()
export class WindowService {
    //----------------------------------------------------------------------------------------------
    // Constructor Method Section:
    //----------------------------------------------------------------------------------------------
    constructor() { }

    //----------------------------------------------------------------------------------------------
    // Public Properties Section:
    //----------------------------------------------------------------------------------------------
    get nativeWindow(): Window {
        return window;
    }
}

回答1:

The error message you get says that the property range for example cannot be found on preferences. The same applies for your WindowService. In your getter you return the window object and in your component you try to access offerResults on that window object. This property does not make any sense on the window object because this object represents an open window in the browser and I would not store any data in that object.