angular - 无法从我的服务调用组件函数
问题描述
我正在使用 observables 从我的服务内部调用我的组件函数,这是我的服务代码:
private trades = new Subject<any>();
// Observable string streams
tradeMethodCalled$ = this.trades.asObservable();
constructor(private http:Http) { }
getAllTrades() {
let headers = new Headers();
console.log('here');
headers.append('Content-Type', 'application/json');
this.http.get('http://localhost:50005/api/trading/trades',{
headers: headers
}).pipe(map((res : any)=>res.json()))
.subscribe(
(res) => {
this.payload = res[0].state.data;
console.log('success');
console.log(this.payload);
this.trades.next();
}
);
}
这是我的组件代码
export class LandingPageComponent implements OnInit {
trades;
party;
constructor(public service: CordaContentService,private routes : ActivatedRoute) {
this.service.tradeMethodCalled$.subscribe(
() => {
console.log(this.trades + "here");
routes.params.subscribe(val => {
this.trades=this.service.gettrades();
console.log(this.trades);
})
});
}
我究竟做错了什么?我的组件功能没有被触发,我正在使用 Angular 6。请提供一个明确的解决方案
解决方案
推荐阅读
- lua - nodemcu gpio中断无法正常工作
- google-apps-script - 获取另一个工作表中单元格的最后更新时间
- python - Spark覆盖广播变量
- mongodb - Mongo 条件 $push
- wordpress - 如何从 Wordfence 禁用身份验证电子邮件发送?
- angular - 使用 Angular 和 Electron 构建的桌面应用程序在安装后显示白屏
- c# - 遇到断点时是否可以在 C# 中仅“暂停”单个工作线程
- typescript - 打字稿错误 TS(2304) jest.MockedFunction - jest.MockedFunction 的正确用法是什么?
- spring-batch - 是否可以在春季批次中将大物体从一个步骤传递到另一个步骤
- r - 在 R 中声明别名函数的最佳方法