我正在尝试在我的Ionic3 typescript应用程序上使用LocalForage库。
在injectable服务中使用LocalForage,如下所示
import {Injectable} from '@angular/core';
import localForage from "localforage"
@Injectable()
export class LocalStorageService {
constructor(private localForage: LocalForage) {
}
getAccessToken() {
return this.localForage.getItem('accessToken').then((token) => token);
};
setAccessToken(token: String){
this.localForage.setItem('accessToken', token);
}
}然后在我的component类上,我有类似这样的东西
...
token:string;
...
this.localStorageService.getAccessToken().then(token=> {
this.token = token;
})并返回以下错误:
TS2345:Argument of type '{}' is not assignable to parameter of type 'string'我哪里做错了?
谢谢
发布于 2017-05-10 18:37:22
在我看来,promise chain中不需要getAccessToken的最后一项,所以您可以尝试如下所示:
getAccessToken() {
return this.localForage.getItem('accessToken');
};https://stackoverflow.com/questions/43888300
复制相似问题