我在这里做Angular教程
下面的代码有双重类型的声明,但我不明白它的含义.
handleError<T>(operation = 'operation', result?: T) {
return (error: any): Observable<T> => {
console.error(error);
this.log(`${operation} failed: ${error.message}`);
return of(result as T);
};
}
Run Code Online (Sandbox Code Playgroud)
所以错误被声明为类型any,然后有另一个冒号来声明一个以Observable作为参数的函数.究竟是什么回归?
我不明白为什么下面的代码会这样工作:所有结果都进入 catch 块。“select * from danceMoves”之后的最后一个 catch 块实际上会将“swag”写入控制台。
这是一个使用 ionic start 创建的简单项目,然后添加 cordova-sqlite-storage。遵循 Ionic 站点文档。
public testSQLite() {
this.sqlite.create({
name: 'data.db',
location: 'default'
})
.then((db: SQLiteObject) => {
db.executeSql('create table if not exists danceMoves(name VARCHAR(32))')
.then(() => { debugger; console.error('Executed SQL') })
.catch(e => { debugger; console.error(e) })
.then(() => { debugger; return db.executeSql("insert into danceMoves(name) values('swag')") })
.then(() => { debugger; return db.executeSql("select * from danceMoves") })
.then(result => { debugger; console.log(result.rows.item(0).name) })
.catch(error => { debugger; console.error(error) }) …Run Code Online (Sandbox Code Playgroud)