2017-06-21 17 views
0

を投げる私は、次のエラーが発生します:私は約束を返すメソッドを呼び出していますというクラスを宣言した約束がエラー

{"__zone_symbol__currentTask":{"type":"microTask","state":"notScheduled","source":"Promise.then","zone":"angular","cancelFn":null,"runCount":0}}

どこ....ここ

export class TechPRODAO { 
sqlite: any; 
db: SQLiteObject; 

constructor() { 
    this.sqlite = new SQLiteMock(); 

    this.sqlite.create({ 
     name: 'techpro.db', 
     location: 'default' 
    }).then((_db: SQLiteObject) => { 
     this.db = _db; 
    }); 
}; 

public executeSql(sqlstatement: string, parameters: any): Promise<any> { 

    return this.db.executeSql(sqlstatement, parameters); 
} 

です私は、コール

export class AppointmentDAO { 
techprodao: TechPRODAO; 

constructor(_techprodao: TechPRODAO) { 
    this.techprodao = _techprodao; 
}; 

public insertAppointment(appointment: Appointment) { 
    console.log("insertAppointment called"); 
    this.techprodao.executeSql("INSERT INTO appointment (ticketnumber, customername, contactemail, contactphone, status, location, paymenttype, description, hascontract) " + 
     "VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?)", [appointment.ticketnumber, appointment.customername, appointment.contactemail, appointment.contactphone, appointment.status, 
      appointment.location, appointment.paymenttype, appointment.description, appointment.hascontract]) 
     .then((data) => { 
      console.log("Inserted into appointment: ticketnumber=" + appointment.ticketnumber); 
     }, (error) => { 
      console.log("ERROR in insertAppointment: " + JSON.stringify(error)); 
     }); 
} 

insertAppointmentはは、ExecuteSQLにエラーがスローされますが、それは当たっていない理由を私は理解していないを作ります"then"を適切に。

+0

イベントが複数回トリガーされていないことを確認する必要があります。 – Ahmad

答えて

1

一般的に、非同期のものをコンストラクタに入れないでください。彼らはいつ準備ができているのか分かりません。代わりに:

export class TechPRODAO { 
    sqlite: any; 
    db: Promise<SQLiteObject>; 

    constructor() { 
    this.sqlite = new SQLiteMock(); 

    this.db = this.sqlite.create({ 
     name: 'techpro.db', 
     location: 'default' 
    }); 
    } 

    public executeSql(sqlstatement: string, parameters: any): Promise<any> { 
    return this.db.then(db => executeSql(sqlstatement, parameters)); 
    } 
} 
+0

私は 'db'ではなく' createdDb'という名前のプロパティを指定します。 'this.createdDb.then(db => ...) 'と読むように。 – unional

+0

私はまだ同じエラーが発生しています。 – Adam