我开始研究异步管道,并且对此深感困惑。
func getAllApi(completion:@escaping DataCallback){
guard isInternetAvailabele() else {
completion(nil)
return
}
// AppSyncManager.Client() is AWSAppSyncClient Object
AppSyncManager.Client().fetch(query: GetlAllPostQuery(input: allInputs), cachePolicy:.fetchIgnoringCacheData) {
(result, error) in
var haveError:Bool = error != nil
if let _ = result?.data?.getAllPostings?.responseCode {haveError = false} else {haveError = true}
if haveError {
print(error?.localizedDescription ?? "")
completion(nil)
return
}
if result != nil{
completion(result)
}else{
completion(nil)
}
}
}
这是我的组件。
Task <06E9BBF4-5731-471B-9B7D-19E5E504E57F>.<45> HTTP load failed (error code: -1001 [1:60])
Task <D91CA952-DBB5-4DBD-9A90-98E2069DBE2D>.<46> HTTP load failed (error code: -1001 [1:60])
Task <06E9BBF4-5731-471B-9B7D-19E5E504E57F>.<45> finished with error - code: -1001
Task <D91CA952-DBB5-4DBD-9A90-98E2069DBE2D>.<46> finished with error - code: -1001
这是我的component.html
我遇到错误import { Component, OnDestroy } from '@angular/core';
import { AngularFireDatabase } from 'angularfire2/database';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
courses$;
constructor(db: AngularFireDatabase) {
this.courses$ = db.list('/courses');
}
}
我是Angular的初学者,所以请帮忙。
答案 0 :(得分:2)
将代码更改为:
this.courses$ = db.list('/courses').valueChanges();
这将解决您的问题。