export class HomeComponent implements OnInit {
data: any;
constructor(private apiService: ApiService) { }
ngOnInit(): void {
// Substitua 'your-endpoint' pelo seu endpoint real
this.apiService.getData('your-endpoint').subscribe(
response => {
this.data = response;
console.log(this.data);
},
error => {
console.error('Error fetching data', error);
}
);
}
}
订阅方法被划掉。
尝试使用具有
next
、error
和 complete
属性的对象,此语法并未弃用。
this.apiService.getData('your-endpoint').subscribe({
next: response => {
this.data = response;
console.log(this.data);
},
error: error => {
console.error('Error fetching data', error);
}
});