即时收到此错误:由以下原因引起:this.todoService.getKidsDetails(...)。subscribe不是函数 TypeError:this.todoService.getKidsDetails(...)。subscribe不是函数
这里是我的路由,其中DetailinfoComponent是主要的详细信息组件
import {
ModuleWithProviders
}
from '@angular/core';
import {
Routes, RouterModule
}
from '@angular/router';
import {
WorkersComponent
}
from './components/workers/workers.component'
import {
AdminComponent
}
from './components/admin/admin.component'
import {
KidsprofComponent
}
from './components/kidsprof/kidsprof.component'
import {
HomeComponent
}
from './components/home/home.component';
import {
AppComponent
}
from './app.component'
import {
ContentManagerComponent
}
from './components/content-manager/content-manager.component'
import {
DetailinfoComponent
}
from './components/detailinfo/detailinfo.component'
const appRouts: Routes = [
{
path: '',
component: HomeComponent
}, {
path: 'kidsProf',
component: KidsprofComponent
},
{
path: 'detail/:id',
component: DetailinfoComponent
}
]
export
const routing: ModuleWithProviders = RouterModule.forRoot(appRouts)
这是一个可以从路线中获取身份的儿童组件
ngOnInit() {
let id = this._route.snapshot.params['id'];
this.kidService.getKidsDetails(id)
.subscribe(kid => this.kid = kid);
console.log(this.kid);
}
服务获取有关特定孩子的firebase数据
public getKidsDetails(id) {
return firebase.database().ref('kids/' + id).once('value');
}
答案 0 :(得分:0)
尝试使用提取路径参数并在kidService中使用它们。
ngOnInit(){
this._route.params
.map(params => params['id'])
.subscribe((id) => {
this.kidService.getKidsDetails(id)
.subscribe(kid => {
this.kid = kid);
console.log(this.kid);
}
})
});
}
和
public getKidsDetails(id) {
return firebase.database().ref('kids/' + id).once('value')
.map(response => response.json());
}