我在登录后使用该ionic/storage包来存储api_tokenfor用户,因此我可以使用唯一令牌与API进行交互.
我面临的问题是我需要获取值,通过storage.get该值返回一个promise并导致我想要设置的标题没有及时设置.
我需要返回一个RequestOptions实例,但无法弄清楚如何添加我从promise中检索到的头.添加与localStorage同步的头文件在测试时工作正常,因此问题必须是异步执行.
createAuthorizationHeader(headers: Headers) {
// this does add the header in time
localStorage.setItem('api_token', 'some token');
headers.append('Authorization', 'Bearer ' + localStorage.getItem('api_token'));
// this does not add the header in time
return this.storage.get('api_token').then((value) => {
headers.append('Authorization', 'Bearer ' + value);
});
}
getHeaders(path): RequestOptions {
let headers = new Headers({
'Accept': 'application/json',
'Content-Type': 'application/json'
});
if(!this.isGuestRoute(path)) {
this.createAuthorizationHeader(headers);
}
return new RequestOptions({ headers: headers });
}
get(path: string) {
return this._http.get(this.actionUrl + path, this.getHeaders(path)) …Run Code Online (Sandbox Code Playgroud) 我目前正在使用API而不是浮点数或整数的货币我收到这样的字符串.
问题在于我需要单独存储价值和货币,但货币需要存储为ISO代码,例如欧元,美元或英镑而不是欧元和美元.
在PHP中是否有任何方法可以使用NumberFormatter或类似的方式根据货币符号获取货币代码?
目前我只有很长的货币符号和名称列表,string_contains('$2.49', '$')用于检查某种货币.