Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Is the method subscribe in angular 17 is not working

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);
      }
    );
  }
}

The subscribe method appears crossed out.

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

The comma separated method of passing next, error and complete callback is deprecated.

.subscribe((data: any) => {}, (err: any) => {}, () => {}); // <- deprecated! 

Try an object with next, error and complete properties, this syntax is not deprecated.

this.apiService.getData('your-endpoint').subscribe({
      next: response => {
        this.data = response;
        console.log(this.data);
      },
      error: error => {
        console.error('Error fetching data', error);
      }
});
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading