Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 获取indexedDb配额存储信息_Angular_Typescript_Indexeddb - Fatal编程技术网

Angular 获取indexedDb配额存储信息

Angular 获取indexedDb配额存储信息,angular,typescript,indexeddb,Angular,Typescript,Indexeddb,我尝试了以下代码来获取indexedDb配额存储信息 navigator.webkitTemporaryStorage.queryUsageAndQuota ( function(usedBytes, grantedBytes) { console.log('we are using ', usedBytes, ' of ', grantedBytes, 'bytes'); }, function(e) { console.log('Error', e); } ); 它不工

我尝试了以下代码来获取indexedDb配额存储信息

navigator.webkitTemporaryStorage.queryUsageAndQuota ( 
function(usedBytes, grantedBytes) {  
    console.log('we are using ', usedBytes, ' of ', grantedBytes, 'bytes');
}, 
function(e) { console.log('Error', e);  }
); 
它不工作,并出现以下错误

类型“Navigator”上不存在属性“webkitTemporaryStorage”


有人能提供在typescript中获取indexedDb配额存储信息的解决方案吗?

问题在于缺少typescript键入。你可以考虑这个问题。

要解决此问题,一种解决方案是声明类型为
any
的变量:

let nav: any = navigator;
nav.webkitTemporaryStorage.queryUsageAndQuota ( 
function(usedBytes, grantedBytes) {  
    console.log('we are using ', usedBytes, ' of ', grantedBytes, 'bytes');
}, 
function(e) { console.log('Error', e);  }
); 
另一种方法是扩展Navigator的接口

interface Navigator {
    webkitTemporaryStorage: {
        queryUsageAndQuota ;
    }
}

你的代码正在工作!我复制并粘贴到浏览器控制台。您收到的错误消息是什么?我没有收到。我在typescript中使用了此代码,并且在类型“Navigator”上不存在获取错误属性“webkitTemporaryStorage”。这是一个与typescript中的键入相关的问题。不客气!别忘了对答案进行投票:)嗨,我在我的appdata文件夹中检查了我的indexeddb大小。它只有180kb。但这段代码给出了761194596字节。你能解释一下使用字节的含义吗?你可以看一下吗