Greetings,
Despite my efforts to resolve this error by researching similar cases, I am unable to apply the solutions to my particular issue (due to being new to this). The problem arises when attempting to invoke a function within user.service.ts
from my add-new-message component.
Here is the content of user.service.ts
:
import {Injectable} from '@angular/core';
import {HttpClient, HttpHeaders} from '@angular/common/http';
import {Observable} from 'rxjs/Observable';
import {GLOBAL} from './global';
import {User} from '../models/user';
@Injectable()
export class UserService{
public url:String;
public identity;
public token;
public stats;
public user;
constructor(public _http: HttpClient){
this.url =GLOBAL.url;
}
getIdentity(){
let identity = JSON.parse(localStorage.getItem('identity'));
if(identity != 'undefined'){
this.identity = identity;
}else{
this.identity= null;
}
return this.identity;
}
getToken(){
let token = localStorage.getItem('token');
if(token != "undefined"){
this.token = token;
}else {
this.token = null;
}
return this.token;
}
As for add.component.ts
:
import {Component, OnInit, DoCheck} from '@angular/core';
import {Router, ActivatedRoute, Params} from '@angular/router';
import {Follow} from '../../../models/follow';
import {Message} from '../../../models/message';
import {MessageService} from '../../../services/message.service';
import {FollowService} from '../../../services/follow.service';
import {User} from '../../../models/user';
import {UserService} from '../../../services/user.service';
import {GLOBAL} from '../../../services/global';
@Component({
selector: 'add',
templateUrl: './add.component.html',
providers: [
FollowService, MessageService, UserService
]
})
export class AddComponent implements OnInit {
public title: string;
public message: Message;
public identity;
public token;
public url: string;
public status: string;
public follows;
constructor(
private _route: ActivatedRoute,
private _router: Router,
private _followService: FollowService,
private _messageService: MessageService,
private _userService: UserService
){
this.title = 'New message';
this.message = new Message('','','','',this.identity._id,'');
this.identity = this._userService().getIdentity();
this.token = this._userService().getToken();
this.url = GLOBAL.url;
}
ngOnInit(){
console.log('add.component loaded');
}
}
Both
this.identity = this._userService().getIdentity();
and this.token = this._userService().getToken();
are resulting in the same error:
This expression is not callable.
Type 'UserService' has no call signatures.
41 this.identity = this._userService().getIdentity();
Thank you for any assistance provided.