问题是,当我在子组件中订阅了GraphService中的某些可观察项(即使它不是getProductGraph
方法)时,
console.log('It happen again!!!!!')
在父组件中订阅将成为我不希望的呼叫。
ngOninit和mergeMap KnowledgeGraphMainComponent
不被调用,仅订阅代码被调用。
这是我的代码: 父组件:使用graphQLService初始化一些数据
export class KnowledgeGraphMainComponent implements OnInit {
nodeTypes: [];
constructor(
private graphQLService: GraphQLService,
public graph: GraphService,
) {
}
ngOnInit() {
this.route.queryParams
.pipe(
mergeMap(queryParams => {
const filterMap = this.initFilterMap(queryParams);
this.filterContainer = new FilterContainer(filterMap);
return this.graphQLService.getAllNodeFields();
}),
mergeMap(fields => {
this.nodeTypes = fields['fields'];
let params = this.filterContainer.getParams();
params = this.sharedUtility.removeEmptyKey(params);
return this.graphQLService.getProductGraph(params);
})
)
.subscribe(result => {
console.log('It happen again!!!!!');
if (!this.graph.simulation || this.event !== '') {
this.graph.graph = this.utility.convertApolloToGraphKA(result['data']['nodes']['products'], EntityName.product);
this.graph.conditionModel.limit = this.filterContainer.filters['page'].limit;
this.graph.conditionModel.offset = this.filterContainer.filters['page'].offset;
if(!this.graph.simulation){
this.graph.initgraph();
}
this.graph.updategraph();
this.event = '';
}
this.spinner.hide();
});
}
}
子组件:使用GraphService并通过父组件传递
export class GraphD3ViewComponent implements OnInit {
@Input() graph:GraphService;
@Input() nodeTyps:[];
constructor(
) {
}
ngOnInit() {
}
}
GraphService需要使用GraphQLService来执行一些http请求
export class GraphService extends Graph {
that: any;
constructor(
private graphQLService: GraphQLService,
) {
super();
}
}
GraphQLService是执行http请求并返回可观察的
类我该如何解决在子组件订阅时不会调用KnowledgeGraphMainComponent中的订阅