シーケンスの2つの約束:フィルターpouchdbドキュメント - 私はpouchdbにドキュメントの2種類を持っている
- トドス - だけのユーザー数が入れ -
- は、ユーザー ドスのリスト別の形式でpochdbに入れます。
私はtodosに書きます。私はuserNoの変数も持っています。このように私は彼が所有するtodosを知っています。 私はtodosとユーザー番号を取得するためにプロバイダに2つの機能を持っています。私はパイプを介してユーザ数でドスをフィルタリングするHTMLリストで
:
<ion-item-sliding *ngFor="let todo of todos | filter : 'numer_p' : this.todoService.userNo">
私は手でこの番号を入力した場合、それは素晴らしい作品。 Todosはこの番号でフィルタリングされます。
問題は、私はhome.ts ionViewLoadedに2つの呼び出しがあるということです。私はのgetUser AFTER getTodosを呼び出す必要が
//call provider to get all docs to show on the list
this.todoService.getTodos().then((data) => {
this.todos = data;
});
//call provider to get userNo from pouchdb and set variable in the provider
this.todoService.getUser().then((result) => {
console.log("getBadacz result:" + JSON.stringify(result));
this.todoService.userNo = result['name'];
}).then(function(second){;
console.log("second");
});
を。だから私はPromisesを使ってこの関数を順番に実行する必要があります。 フィルタが設定されていないため、フィルタのthis.todoService.userNoは未定義です。そして、それは動作しません。
私はこのようにそれを実行しようとしました:
this.todoService.getUser().then((result) => {
console.log("getBadacz result:" + JSON.stringify(result));
this.todoService.userNo = result['name'];
}).then(function(second){;
console.log("second");
this.todoService.getTodos().then((data) => {
this.todos = data;
});
});
しかし、エラーがあります:
EXCEPTION: Error: Uncaught (in promise): TypeError: Cannot read property 'todoService' of null
私は、これはシーケンスではなく、成功せず約束アレンジしてみました。ここで
あなたは、プロバイダでの関数の実装を見つけることができますフィドルです: Filter pouchdb docs by userID saved in another doc
はあなたの助けのためにありがとうございました。
angular2ですか?あなたのhtmlテンプレートの 'this.todoService.userNo'から' this.'を削除してみてください。 – yurzui
私はそれが "ラッシュ"問題であると思いました。それは私がこれを複雑にしているようです:)ありがとう!できます。 –