Within my Angular2 application, I have a class that includes several properties which will be assigned values within components.
@Injectable()
export class Globals {
private token: string;
private authorization: string;
private roleUser: boolean;
private roleAdmin: boolean;
constructor(){}
setToken(token: string){
this.token = token;
}
getToken(){
return this.token;
}
}
When attempting to assign a string value to the token property in a component, the following error occurs:
Type 'string' is not assignable to type '(token: string) => void
Here is how the value assignment is done in the controller:
this._globals.setToken = this._token; //this._token is a string
Why am I encountering this error? I am simply trying to set a string value to a property that accepts a string parameter.