Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

error TS2304: Cannot find name 'Observable' Angularjs 2

When I swithch to my Linux PC I get error like this:

app/app.module.ts(21,67): error TS2304: Cannot find name 'Observable'.
app/app.module.ts(25,53): error TS2304: Cannot find name 'Observable'.
app/app.module.ts(29,68): error TS2304: Cannot find name 'Observable'.
app/app.module.ts(33,67): error TS2304: Cannot find name 'Observable'.
app/app.module.ts(37,56): error TS2304: Cannot find name 'Observable'.
app/app.module.ts(52,27): error TS2304: Cannot find name 'Observable'.
app/app.module.ts(52,50): error TS2304: Cannot find name 'Observable'.
app/app.module.ts(54,40): error TS2304: Cannot find name '_'.
app/app.module.ts(56,24): error TS2304: Cannot find name 'Observable'.
app/app.module.ts(58,24): error TS2304: Cannot find name 'Observable'.

Anyone know solution for this?

Also my editor show errors on HttpIntreceptor Class, when I remove it it works fine...

This part is marked: Observable<Response>

Could you check it:

class HttpInterceptor extends Http {

    constructor(backend: ConnectionBackend, defaultOptions: RequestOptions, private _router: Router) {
        super(backend, defaultOptions);
    }

    request(url: string | Request, options?: RequestOptionsArgs): Observable<Response> {
        return this.intercept(super.request(url, options));
    }

    get(url: string, options?: RequestOptionsArgs): Observable<Response> {
        return this.intercept(super.get(url,options));
    }

    post(url: string, body: string, options?: RequestOptionsArgs): Observable<Response> {   
        return super.post(url, body);
    }

    put(url: string, body: string, options?: RequestOptionsArgs): Observable<Response> {
        return this.intercept(super.put(url, body, this.getRequestOptionArgs(options)));
    }

    delete(url: string, options?: RequestOptionsArgs): Observable<Response> {
        return this.intercept(super.delete(url, options));
    }

    getRequestOptionArgs(options?: RequestOptionsArgs) : RequestOptionsArgs {
        if (options == null) {
            options = new RequestOptions();
        }
        if (options.headers == null) {
            options.headers = new Headers();
        }
        options.headers.append('Content-Type', 'application/json');
        return options;
    }

    intercept(observable: Observable<Response>): Observable<Response> {
        return observable.catch((err, source) => {
            if (err.status  == 401 && !_.endsWith(err.url, 'api/auth/login')) {

                return Observable.empty();
            } else {
                return Observable.throw(err);
            }
        });

    }
}
like image 322
Vladimir Avatar asked Oct 11 '16 17:10

Vladimir


1 Answers

I had the same issue fixed it by importing Observable

import {Observable} from 'rxjs/Rx';
like image 104
Taha Zgued Avatar answered Nov 15 '22 20:11

Taha Zgued