Is there a way to globally assign a value outside of a method within my app component?
This is how my service is structured:
import { NumberInput } from '@angular/cdk/coercion';
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { Candidato } from "../interfaces/candidato";
import { Cuestionario } from '../interfaces/cuestionario';
import { Respuesta } from '../interfaces/Respuesta';
import { Verdaderos } from '../interfaces/verdaderos';
@Injectable({
providedIn: 'root'
})
export class CandidateService {
url="http://localhost:3000/api"
constructor(private http:HttpClient) { }
// Methods go here...
The interface "Verdaderos" is defined like this:
export interface Verdaderos{
Pregunta: number;
}
After retrieving data from the service, an array object containing IDs related to specific responses needs to be counted for sorting purposes. However, the issue I'm facing is with assigning these values to global variables in order to plot them using ngx-charts.
Here is part of the method attempting to count the responses:
// Method logic goes here...
this.N = countN2;
this.M = countM2;
this.P = countP2
})
}
Despite successfully printing the desired values via console, I haven't succeeded in assigning them to the global variable needed for plotting using ngx-charts.
The HTML structure required for rendering a pie chart looks like this:
<div class="wrapperuser">
<div class="container-sm grafico">
<ngx-charts-pie-chart
[view]="view"
[results]="single"
[gradient]="gradient"
[legend]="showLegend"
[labels]="showLabels"
[doughnut]="isDoughnut">
</ngx-charts-pie-chart>
</div>
</div>