maria
maria

Reputation: 159

angular2/4 cant find object

Why do i get cannot find object?

I get the following error :

core.service.ts (19,23): Cannot find name 'object'.

in line:

 userChange: Subject<object> = new Subject<object>();

i do have these imports:

import { Injectable } from '@angular/core';
import { Http, RequestOptions, URLSearchParams } from '@angular/http';
import {Observable, } from 'rxjs/Observable';
import { Comment } from './models/comment'
import 'rxjs/add/operator/map';
import 'rxjs/Rx';

import {Subject} from 'rxjs/Subject';

import { Router, NavigationEnd, CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';

@Injectable()
export class CoreService {

  constructor(private http: Http, private router: Router) { }

   userChange: Subject<object> = new Subject<object>();


further...

Upvotes: 1

Views: 1696

Answers (3)

SrAxi
SrAxi

Reputation: 20005

You have to use <any>.

userChange: Subject<any> = new Subject<any>();

Here you find the any documentation, in the example code you will see the difference between using Object and any.

I would approach your code this way (personal preference):

userChange$: Observable<any>;  // We declare the Observable

private userChangeSubject = new Subject<any>();  // We declare the Subject

constructor(private http: Http, private router: Router) {
     this.userChange$ = this.userChangeSubject.asObservable();  // We 'associate' the Subject with the Observable
}

updateUser(someUserParams) {
        this.userChangeSubject.next(someUserParams); // We then proceed to apply our logic and anyone subscribe to 'userChange$' will receive these someUserParams when this method is triggered
}

Upvotes: 1

martin
martin

Reputation: 96891

The object type was added in TypeScript 2.2, are you sure you're using the right TypeScript version?

For more info see: What's-new-in-TypeScript#object-type

Upvotes: 0

Igor
Igor

Reputation: 62213

You probably meant Object with a capital O. JavaScript / Typescript is case sensitive.

userChange: Subject<Object> = new Subject<Object>();

Upvotes: 2

Related Questions