我正在尝试通过异步管道加载ngfor中的服务数据,但我遇到了一个问题: 这是我的组成部分:
<app-book-list *ngFor="let app of apps | async | serachBox:searchBooksByName | filterSearch:showTechBooks:showMgmBooks:showFictionBooks "
[bookdetails]="app"></app-book-list>
在这个组件中,应用程序应该来自服务。
在我的component.ts文件中:
public apps= [];
ngOnInit() {
this.ServerService.getBookDetails()
.then((data)=>{
this.apps = data;
})
}
以下是承诺:
getBookDetails(){
let promise = new Promise((resolve,reject)=>{
return this.http.get('https://lib-http-ng.firebaseio.com/bookdetails.json')
.toPromise()
.then((res)=>{
const data = Object.values(res.json());
resolve(data[0])
})
})
return promise;
} 我收到与异步管道相关的错误。
1
Type '{}' is not assignable to type 'Promise<any>'.
答案 0 :(得分:0)
Dropit()
{
setLayout(null);
tf = new JTextField();
tf.setBounds(50, 50, 100, 100);
add(tf);
map.put("mon", mon);
map.put("tue", tue);
lis = new JComboBox<String>(days);
lis.setSelectedItem("sat");
lis.addActionListener(this);
lis.setBounds(100,100,100,100);
add(lis);
pop = new JComboBox<String>();
pop.setBounds(200,100 , 100, 100);
pop.setVisible(false);
add(pop);
setVisible(true);
setSize(500,500);
}
public void actionPerformed(ActionEvent e)
{
lis = (JComboBox<String>) e.getSource();
String name = (String) lis.getSelectedItem();
tf.setText(name);
if (map.containsKey(name))
{
pop.removeAllItems();
for (String s: map.get(name))
pop.addItem(s);
pop.setVisible(true);
} else
pop.setVisible(false);
}
应该是
this.ServerService.getBookDetails()
.then((data)=>{
console.log(data);
this.apps = data;
})
或删除this.apps = this.ServerService.getBookDetails()