** 角 9 **
home.component.ts
'我正在尝试在 html 页面中匹配 firebase 数据库中的类型和显示数据存储,任何人都可以解决这个错误。两天以来,我一直在努力解决这个错误。
import { Component, OnInit } from '@angular/core';
import { HttpService } from 'src/app/http.service';
@Component({
selector: 'app-home',
templateUrl: './home.component.html',
styleUrls: ['./home.component.css']
})
export class HomeComponent implements OnInit{
constructor(private http:HttpService) { }
users : any[] = [
];
Oncreateuser(uname:any,fame:any){
this.users.push({
name:uname.value,
name2:fame.value
})
uname.value = ""
fame.value = ""
}
save(){
this.http.saveitems(this.users).subscribe(
(Response) => console.log(Response),
(err) => err
)
alert('saved to firebase Database')
}
onremoveitem(item:any){
this.users.splice(item, 1)
}
ngOnInit(){}
fetchproduct(){
this.http.fetch().subscribe((Response)=>{
console.log(Response)
},(err)=>console.log(err))
}
}
答案 0 :(得分:0)
请更改此行
this.http.fetch()
.subscribe(Response=>{this.users = Response})
到
this.http.fetch()
.subscribe((Response:any)=>{this.users = Response})
答案 1 :(得分:-1)
只需声明以下内容:
users: any = [];
而不是这个:
users: any[] = [];