我想发送变量" dataJSONparse "从服务到组件
服务
listOfUsers() {
this.items = <FirebaseListObservable<any>>this.af.list('/user', {
query: {
orderByChild: 'name'
}
}).map((user) => {
return user.map(user_data => {
user_data.name;
user_data.mobile;
return user_data;
})
})
this.userDataQuery = this.items.subscribe(x => this.forx(x));
}
public dataJSONparse: any;
forx(x) {
this.dataStringify = JSON.stringify(x);
this.dataJSONparse = JSON.parse(this.dataStringify);
console.log("test print from service: ",this.dataJSONparse);
}
组件
ngOnInit(): void {
console.log("test",this.heroservice.dataJSONparse);
}
控制台错误
从组件未定义测试
从服务测试打印:数组[对象,对象,对象,对象,对象,对象]