当我尝试订阅 Subject folder_id 时,当我在 files 组件中传递 id 时,它没有订阅 board 组件。
当在文件组件中按下按钮时会触发此 boardId 函数。activateId 是从 url 的快照中获取的 id。
boardID(){
this.apiService.folder_id.next(this.activateID.id);
console.log(this.activateID.id);
}
这是 board 组件中的 ngOnInit,它必须订阅从 files 组件发出的 id。但是由于某种原因,当我尝试获取此组件中的 id 时,它不会运行此订阅功能。
ngOnInit() {
this.apiService.folder_id.subscribe(
(_id : string) => {
this.id = _id;
console.log(this.id)
}
);
this.page = 0;
console.log('Screen width :', this.scrWidth, 'Screen height', this.scrHeight);
// getting the 2D context of Canvas element
this.canvasElement = this.canvas.nativeElement;
this.ctx = this.canvasElement.getContext('2d');
// setting the Width and Height to the canvas element
this.renderer.setAttribute(this.canvasElement, 'width', this.scrWidth);
this.renderer.setAttribute(this.canvasElement, 'height', this.scrHeight);
// for background
this.backgroundCanvas = this.background.nativeElement;
this.renderer.setAttribute(this.backgroundCanvas, 'width', this.scrWidth);
this.renderer.setAttribute(this.backgroundCanvas, 'height', this.scrHeight);
}
现在这是 service.ts 文件:-
import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Router } from '@angular/router';
import { environment } from 'src/environments/environment';
import { Subject } from 'rxjs';
@Injectable({
providedIn: 'root'
})
export class RestService {
xAuthToken = null;
boardId = null;
gerBoardDetails = null;
createFolderResponse = null;
deleteFolderResponse = null;
folder_id = new Subject<string>();
constructor(private http: HttpClient, public router: Router) {}
有人可以帮我解决这个问题吗,我已经坚持了很多天了。谢谢你。