0

Subject folder_id をサブスクライブしようとしているときに、ファイル コンポーネントで ID を渡しているときに、ボード コンポーネントでサブスクライブしていません。

この boardId 関数は、ファイル コンポーネントでボタンが押されるとトリガーされます。activateId は、URL のスナップショットから取得した ID です。

  boardID(){
    this.apiService.folder_id.next(this.activateID.id);
    console.log(this.activateID.id);
  }

これは、ファイル コンポーネントから発行される ID をサブスクライブする必要があるボード コンポーネントの ngOnInit です。しかし、何らかの理由で、このコンポーネントで 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) {}

誰かがこの問題について私を助けてくれませんか、私は何日もこれにこだわっています。ありがとうございました。

4

3 に答える 3