【发布时间】:2016-10-06 12:50:54
【问题描述】:
我正在 ionic 2 中编写一个简单的应用程序,但我的 anc(Angular 编译器)有问题,因为当我运行 ionic serve 它给我警告但应用程序在浏览器上正常运行,但是当我尝试构建对于我的手机,它坏了,构建过程会导致错误。
var tempResults: ResultModel = new ResultModel(currentOne.id, (me.res.length > 1) ? me.res[0] : me.res[0], (me.res.length > 1) ? me.res[1] : me.res[0], currentOne.question, currentOne.imagePath);
console.log(localforage.hasOwnProperty('result'))
localforage.getItem('results').then(data=> {
var allResponses: Array<ResultModel> = new Array<ResultModel>();
if (data != null) {
var allResponses: Array<ResultModel> = <Array<ResultModel>>JSON.parse(data);
allResponses.push(tempResults);
localforage.setItem('results', JSON.stringify(allResponses));
} else {
allResponses.push(tempResults);
localforage.setItem('results', JSON.stringify(allResponses));
}
});
触发错误的行是: var allResponses: Array = >JSON.parse(data);
错误是:
ngc 错误:错误:C:/Users/.../result-item.ts:23:52 错误:“{}”类型的参数不可分配给“字符串”类型的参数。
我在编译器中遇到类型错误,我开始认为这可能是一个错误。
【问题讨论】:
-
.then((data: string) => {或许可行
标签: angular typescript ionic2