None
None

Reputation: 9247

Is it possible to send data from one service to another?

In my loginService i have this:

getUserData(): any { return this.userData; }

What i want is to get that in logsService:

data = this.getUserData();
return this.http.get('/api/logs' + data.user.email)
                               // ...and calling .json() on the response to return data
                                .map((res:Response) => res.json())
                                //...errors if any
                                .catch((error:any) => Observable.throw(error.json().error || 'Server error'));

            }

Is that possible?

Upvotes: 0

Views: 63

Answers (1)

Jaroslaw K.
Jaroslaw K.

Reputation: 5374

It's possible. You should inject service in constructor, in the same way as inject service to component, f.e.

@Injectable()
export class FirstService {

    constructor(
        private _secondService: SecondService
    ){}

}

@Injectable()
export class SecondService {

    constructor( ){}

}

Upvotes: 1

Related Questions