我正在尝试从angularJS的nodeJS API中获取数据,我声明了一个变量,并且我想影响服务器对其的响应,这是我的代码:
export class SondageSingleComponent implements OnInit, AfterViewInit {
@ViewChild('containerPieChart') element: ElementRef;
survey: any = {};
currentUser: any;
statistics: any;
colorCounter: any = 0;
d3Colors: any[] = ["#3182bd", "#6baed6", "#9ecae1", "#c6dbef", "#e6550d"];
private host: D3.Selection;
private svg: D3.Selection;
private width: number;
private height: number;
private radius: number;
private htmlElement: HTMLElement;
private pieData = [];
constructor(
private http: HttpClient,
private route: ActivatedRoute,
private router: Router,
private toastr: ToastrService
) { }
ngOnInit() {
this.route.params.subscribe(params => {
this.http.get('/api/surveys/' + params.id).subscribe(survey => {
this.survey = survey;
// console.log(this.survey)
debugger
this.http.get('/api/surveys/getStatistics/' + params.id).subscribe(statistics => {
this.statistics = statistics;
this.statistics.options.forEach(option => {
this.pieData.push(option.number);
option.color = this.d3Colors[this.colorCounter];
this.colorCounter = this.colorCounter + 1;
});
});
}, error => {
if (error.status === 400) {
this.showError(error.error.error, 'Erreur!');
if (error.error.error === 'Le sondage demandé n\'existe plus!') {
this.router.navigateByUrl('/sondage');
}
}
});
});
}
数据成功地来自节点端,当我尝试影响数据以调查变量并进行尝试时,任何人都可以说出为什么无法读取this.survey吗?