Тёмный
No video :(

How to fetch data from an API and display it in Angular 17? 

AyyazTech
Подписаться 9 тыс.
Просмотров 19 тыс.
50% 1

Опубликовано:

 

27 авг 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 45   
@AyyazTech
@AyyazTech 15 часов назад
🔍 Want to dive deeper into Angular and full-stack development? Check out my comprehensive course: "Create Full-Stack Blog & CMS with Angular 18, Node.js, MySQL" bit.ly/angular-18-course In this course, you'll: - Build a complete, production-ready blog and CMS - Master Angular 18, Node.js, and MySQL - Deploy your app to Google Cloud Run Perfect for both beginners and experienced devs looking to level up their skills. 🎓 Enroll now: bit.ly/angular-18-course
@fernwoitschach8642
@fernwoitschach8642 8 месяцев назад
I'm new to Angular and all the others tutorial are "pre-standalone=true by default". So this help me a lot. Thank you very much.
@AyyazTech
@AyyazTech 8 месяцев назад
I'm really glad to hear the video was helpful, especially as you navigate the changes in Angular with features like standalone components! It's great that you're staying updated with the latest practices. If you have any more questions or need further clarification as you continue your learning journey, don't hesitate to reach out. Remember to subscribe to the AyyazTech channel and click the bell icon to get notifications for more content that could help you along the way. Welcome to the world of Angular, and happy coding!
@alyssabuensuceso3733
@alyssabuensuceso3733 8 месяцев назад
Thanks so much for this video! It's work!!!
@AyyazTech
@AyyazTech 8 месяцев назад
That's fantastic to hear! I'm so glad the video was helpful and that everything worked out for you. If you have any more questions or need further assistance, feel free to ask. Also, don't forget to subscribe to AyyazTech for more helpful tutorials and tech tips. Hit the bell icon to stay updated on our latest videos. Your support and feedback help us create content that matters to you. Happy coding! 👍💻🎉🔔
@mohiburrahman5639
@mohiburrahman5639 9 месяцев назад
Thank you very helpful ofcourse for me!!
@AyyazTech
@AyyazTech 9 месяцев назад
You're very welcome! I'm thrilled to know you found the information helpful. If you have any more questions or need further assistance, feel free to ask. And remember, for more useful tips and insights, subscribe to the AyyazTech RU-vid channel. Don't forget to like, share, and click the bell icon for the latest updates. Your support is greatly appreciated! 🌟👍🔔
@firasjelassi7992
@firasjelassi7992 5 месяцев назад
a life saver man 🥰🥰🥰🥰
@ahmedraza5114
@ahmedraza5114 3 месяца назад
Good Work
@miggyisabeast
@miggyisabeast Месяц назад
THANK YOU!
@sanjai7760
@sanjai7760 Месяц назад
HttpclientModule is deprecated.... Solve the problem please.....
@harshadnpurohit
@harshadnpurohit 6 месяцев назад
Hello Ayyaz, Your videos are of great help. I am stuck at using FASTAPI reponse model in angular 17 as it returns a FASTAPI object based on response model. Can you post a similar video on how to consume data from FASTAPI? It will be great help.
@DSHeroX
@DSHeroX 2 месяца назад
This has been up for a while so I doubt ill get a response, but im using angular 18, so of course i do know its different, but it all essentially worked up until the HttpClientModule import at about 3:30. It says its deprecated and I am not sure what to do instead for the import to make it work. any advice would be greatly appreciated, thank you. Also thanks for the vid nonetheless
@AyyazTech
@AyyazTech 2 месяца назад
Hi there! Thanks for your comment and the feedback on the video. 😊 Yes, Angular 17 introduces some changes in how you should use `HttpClientModule`. Instead of importing it directly, you now need to use `provideHttpClient(` in your `app.config.ts` file. Here's how you can do it: 1. Update app.config.ts: import { provideHttpClient } from '@angular/common/http'; export const appConfig = { providers: [provideHttpClient(] }; This change will make the `HttpClient` globally available throughout your Angular application. Further I have made a dedicated video covering the new features introduced in angular 17. I suggest you to watch that complete video to know what's new in this. ==> Mastering Angular 17: A Deep Dive into the Latest Features ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-RZg6XEGu9EM.html You might also find these resources helpful: Videos: - How to use Http Interceptor in Angular 17 ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-hy_8JsOIVug.html - How to fetch data from API in Next js 14+ ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-GgvE5fkIs9o.html - How to commit changes to your GitHub repository - A step-by-step guide ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-0fsfRCBNM4I.html Articles: - How to use OpenAI API with Python 3 www.ayyaztech.com/blog/how-to-use-openai-api-with-python-3 - Creating your first chatbot with Langchain and OpenAI: A step-by-step tutorial www.ayyaztech.com/blog/creating-your-first-chatbot-with-langchain-and-openai-a-step-by-step-tutorial Feel free to ask if you have any more questions or need further assistance. Don't forget to like the video, subscribe to the channel, and click the bell icon for notifications! 🔔 Happy coding! 🚀
@indodigi551
@indodigi551 7 месяцев назад
hi why on my infect console show data-display.component.ts:23 ERROR TypeError: newCollection[Symbol.iterator] is not a function
@AyyazTech
@AyyazTech 7 месяцев назад
It sounds like you're encountering an issue with iterating over a collection in Angular. The error newCollection[Symbol.iterator] is not a function typically occurs when you're trying to use a for...of loop or a similar iteration mechanism on something that isn't iterable, like an object or null value. In the context of the video you mentioned, which focuses on fetching and displaying data from an API using Angular, this error could happen if the data returned from the API isn't in the expected iterable format (like an array). Here are a few steps to debug this issue: Check the Data Type: Ensure that the variable newCollection (or the actual variable you're iterating over in your code) is indeed an array. You can log its type using console.log(typeof newCollection). Inspect the API Response: Directly inspect the API response in your browser's developer tools or by logging it to the console before trying to iterate over it. Make sure it's what you expect it to be (usually an array). Default Values: If the data might not be available immediately (e.g., waiting for an API response), ensure you have sensible defaults set up, like initializing your variable as an empty array until the data loads. Error Handling: Implement error handling in your data fetching logic to catch any issues from the API side and handle them gracefully. Remember, the exact solution may vary based on your specific implementation and the data you're working with. If you continue to have issues, feel free to provide more details or check out other community posts with similar issues. Don't forget to subscribe to AyyazTech for more tips and tutorials, and let us know in the comments if you have any more questions. We're here to help!
@Mo-salmm11
@Mo-salmm11 8 месяцев назад
Hello, i have a question here , if i'm using a service, how can i solve this error in the video?
@AyyazTech
@AyyazTech 8 месяцев назад
Hello! If you're encountering an error with your service when trying to fetch data from an API in Angular 17, as shown in the video, here are a few common issues and solutions to consider: HTTP Client Module: Ensure that the HttpClientModule is imported in your module (or the specific standalone component if you're using Angular's new standalone components feature). Without this, Angular won't be able to inject the HttpClient service. Service Injection: Verify that you've correctly injected the HttpClient service in your component or service where you're trying to make the HTTP request. The injection should be done in the constructor or using the inject function for standalone components. API Endpoint: Confirm that the API endpoint you are trying to fetch data from is correct, operational, and not encountering any server-side issues. Try hitting the API endpoint directly in the browser or using tools like Postman to ensure it's working. CORS Policy: If your API is on a different domain, ensure that the server is configured to allow your application's domain using Cross-Origin Resource Sharing (CORS) headers. Error Handling: Implement error handling in your subscription to the HTTP request. Catching errors can provide more insight into what might be going wrong. For example: this.httpClient.get(url).subscribe(data => { // Handle successful response }, error => { console.error("There was an error!", error); }); Observable Subscription: Ensure that you've subscribed to the observable returned by the HttpClient.get() method. HTTP requests in Angular are observable-based and won't be sent until they are subscribed to. Check Console and Network Tab: Look at the browser's developer console for any errors and check the network tab to see if the request was made and what response was received from the server. Angular Version Compatibility: Although rare, there might be changes or deprecations between Angular 16 and 17. Review the Angular update guide for any breaking changes that might affect HTTP requests. By addressing these common issues, you should be able to pinpoint and solve the problem with your HTTP interceptor or service. If the issue persists, please provide any error messages or additional context for a more targeted solution. And don't forget to like, share, and subscribe to AyyazTech for more helpful tutorials and tech tips!
@tyjeait
@tyjeait 9 месяцев назад
is there any reason for not using a service to fetch the data? I made a similar project but I used a service instead, I'm new to angular and don't know what is the best practice.
@aboutselphy
@aboutselphy 9 месяцев назад
Service would be only needed if you use it mutiple times, if you have 2 components who use the same function it would make more sense to use the service instead of copy & past it all the time :)
@AyyazTech
@AyyazTech 9 месяцев назад
Using a service in Angular for data fetching is actually a good practice, especially for more complex apps. It keeps your code organized and makes it easier to reuse data fetching logic across different components. The tutorial might have kept things simple for beginners, but as you grow in Angular, using services for such tasks is definitely the way to go! 😊👍 Keep exploring and don't hesitate to try out different approaches. And remember, if you have more questions or need guidance on specific topics, feel free to ask. Happy coding! 💻🚀
@AyyazTech
@AyyazTech 9 месяцев назад
Yes @aboutselphy You're absolutely right! Services in Angular are ideal for sharing data or logic across multiple components. If the same function is used in several places, a service prevents code duplication and makes maintenance easier. It's all about finding the right balance for your project's needs. Thanks for adding that insight! 😊👍 Keep sharing your thoughts and experiences, it's great for the community. And if you have more questions or tips, feel free to share them. Don't forget to subscribe for more discussions! 🚀💬
@sachinpareek7420
@sachinpareek7420 3 месяца назад
how to access this.data out of the subscribe ?
@lanceigot1999
@lanceigot1999 8 месяцев назад
Hi I have a question, I just started in Angular 17 how do I deploy an Angular 17 project? when I build my angular it has Browser Folder and Server folder in dist whats the purpose of Server? I am using Laravel as backend btw.
@AyyazTech
@AyyazTech 8 месяцев назад
Deploying an Angular 17 SSR project, especially when using Laravel as a backend, can be a bit complex due to the architecture of both technologies. The "server" folder in your Angular build directory is related to the server-side rendering aspect of Angular Universal. This part of your Angular application is responsible for rendering components on the server side before sending them to the client, improving performance and SEO. For deployment, you would typically deploy your Angular SSR app and Laravel API separately. The Angular app could be deployed on a web server or a cloud service that supports Node.js environments, as Angular SSR requires a Node.js server to run. AWS Elastic Beanstalk is one option for such deployments​​. Laravel, being a PHP framework, would be deployed on a server or platform that supports PHP, like a traditional LAMP stack environment. Each part of your application (Angular SSR front-end and Laravel back-end) needs to be accessible to the other. The Angular app will make API requests to the Laravel server, so proper CORS configuration is necessary to allow these cross-origin requests. Given the technical nature of this process, I recommend looking for specific tutorials or guides on deploying Angular SSR applications with a Laravel back-end for detailed steps. If you have further questions or need assistance with specific aspects of the deployment, feel free to ask!
@mohiburrahman5639
@mohiburrahman5639 9 месяцев назад
could you show how can we use service & toatstr service also like angular version 14 or 15 even 16. please!!!
@AyyazTech
@AyyazTech 9 месяцев назад
It's great to see your interest in learning about services and Toastr in Angular, specifically for versions 14, 15, or 16. Your request is noted, and we'll certainly consider creating a detailed tutorial covering these topics in future videos. In the meantime, don't forget to subscribe to the AyyazTech RU-vid channel to stay updated with our latest content. We regularly upload tutorials that can be very helpful for your learning journey. Also, if you like our content, please share it with others who might find it useful, and don't hesitate to drop your questions or suggestions in the comments section. Your feedback helps us improve and cater to your learning needs. And, of course, hit the bell icon to receive notifications about our new videos. Thank you for your support and interest! 🔔🌟👍💻
@luqmanusman70
@luqmanusman70 8 месяцев назад
Hi, how can I connect any database with Angular 17 SSR ?
@AyyazTech
@AyyazTech 8 месяцев назад
To connect a database with Angular 17 SSR, follow these steps: Set up a backend server (like Node.js with Express). Configure the database connection in the backend (e.g., MongoDB, MySQL). Create API endpoints in the backend for database operations. In Angular, create services to make HTTP requests to these endpoints. Use Angular Universal for server-side rendering. Ensure CORS is configured on your backend to allow Angular to access it. Remember, Angular interacts with the database through a backend server. For more tutorials on Angular and web development, subscribe to AyyazTech and click the bell icon for updates.🔔💡🌐
@AyyazTech
@AyyazTech 8 месяцев назад
To connect a database with Angular 17 SSR, follow these steps: Set up a backend server (like Node.js with Express). Configure the database connection in the backend (e.g., MongoDB, MySQL). Create API endpoints in the backend for database operations. In Angular, create services to make HTTP requests to these endpoints. Use Angular Universal for server-side rendering. Ensure CORS is configured on your backend to allow Angular to access it. Remember, Angular interacts with the database through a backend server. For more tutorials on Angular and web development, subscribe to AyyazTech and click the bell icon for updates.🔔💡🌐
@luqmanusman70
@luqmanusman70 8 месяцев назад
Hi, I will really appreciate an example or video tutorials on this.
@luqmanusman70
@luqmanusman70 8 месяцев назад
Do I still need Angular Universal with Angular 17 SSR? As per my understanding, Express Server is built-in with Angular 17 SSR, kindly clarify please.
@user-bq4hl9cq8v
@user-bq4hl9cq8v 5 месяцев назад
Can we call the api in service when application loads then store data and use it as global state , in multiple components ?
@user-yf9cp4pg5n
@user-yf9cp4pg5n 4 месяца назад
It should be in a service yes. All communication with the backend is better services. Code structure make it easy.
@alishoaib3932
@alishoaib3932 2 месяца назад
Its not a good approch to call API directly in component.You should create service for api call and then inject that service in ur component
@mohiburrahman5639
@mohiburrahman5639 6 месяцев назад
hello could you make a video fetch data from rest api like nodejs (backend). real project. because i cant display my data but console is ok. thank you.
@AyyazTech
@AyyazTech 6 месяцев назад
Hello! Thank you for suggesting a video on fetching data from a REST API using Node.js for a real-world project. It's a great idea, especially since many developers encounter challenges when integrating front-end and back-end systems. I'll definitely add this topic to our potential content list. It would be a valuable tutorial to demonstrate the process of fetching data from a REST API, handling common issues, and displaying it effectively in a front-end application. Keep an eye on the AyyazTech channel for this upcoming tutorial! In the meantime, if there are specific aspects of this process you're struggling with, feel free to ask, and I'll do my best to assist. And remember, for more content like this, subscribe to our channel, click the bell for notifications, and share our videos with others who might find them helpful! 🌟👩‍💻👨‍💻📡
@sahiljadhav519
@sahiljadhav519 5 месяцев назад
Please make video to post the data on api
@nicandromartinezsotelo3300
@nicandromartinezsotelo3300 5 месяцев назад
it is basically same code structure as exampled but with change on the command
@mohiburrahman5639
@mohiburrahman5639 9 месяцев назад
thank you for you reply. infact my problem is i cant use srervice in angular 17 for registration. always is error. but same services when i use version 16 . its work fine. without standalone no problem. But with standalone i think i cant use properway services. could you help me pls for registration services how to use version 17.
@AyyazTech
@AyyazTech 8 месяцев назад
To use services in an Angular 17 application, particularly with standalone components, here's a guide: 1. Using the `@Injectable` Decorator: The `@Injectable` decorator is commonly used to define services in Angular. When you decorate a class with `@Injectable`, you can specify where the service should be provided using the `providedIn` property. This property accepts a string value indicating the injector for the service. For instance, using `providedIn: 'root'` means the service is available throughout the entire application, similar to declaring it in the root module. Example: ```typescript import { Injectable } from '@angular/core'; @Injectable({ providedIn: 'root' }) export class MyService { constructor() { } // ... add methods and properties } ``` 2. Registering Providers in Standalone Components: In Angular 17's standalone components, providers are declared using the `bootstrapApplication()` function. This function takes an object as the second argument, where you can provide other Angular modules using the `importProvidersFrom()` function. This method is essential for registering services in standalone components, as traditional methods like adding providers to a component's decorator or an NgModule aren't applicable here. Example: ```typescript bootstrapApplication(AppComponent, { providers: [importProvidersFrom(MatButtonModule)] // Example with Angular Material }); ``` 3. General Information about Providers: Providers in Angular define how a dependency should be instantiated. They can be any object or value but are most commonly classes that provide a service or functionality. Angular offers several ways to define providers, such as through the providers array in an Angular module, the providers property in a component decorator, or by using the `@Injectable` decorator. Given this information, to address your issue of using services in Angular 17 with standalone components, it's important to adapt your approach to service registration. If you're facing errors with service registration, ensure you're using the `@Injectable` decorator correctly and leveraging the `bootstrapApplication()` function for standalone components. This approach differs from traditional module-based architecture, so adapting to these changes in Angular 17 is crucial. If you need further clarification or face specific issues, please feel free to ask. And don't forget to subscribe to AyyazTech for more Angular tips and updates. We're here to help you navigate these new features in Angular 17! 🔔👨‍💻🌐
@kashishrajput-ob8tv
@kashishrajput-ob8tv 5 месяцев назад
How to add pagination in this API ?
@AyyazTech
@AyyazTech 5 месяцев назад
Adding pagination to API data in Angular involves manipulating the data fetched from the API to display it in segments or "pages" within your application. For the "How to fetch data from an API and display it in Angular 17?" tutorial, you can enhance the implementation to include pagination by following these steps: 1. **API Endpoint Modification:** Ensure the API you're fetching data from supports pagination. Many REST APIs provide parameters for pagination, such as `limit` (number of items per page) and `page` or `offset` (which page or data offset to fetch). 2. **Fetching Data with Pagination:** Modify the HTTP GET request in your Angular service or component to include pagination parameters. For example, you can append query parameters to your request URL: `api.example.com/posts?page=1&limit=10`. 3. **Pagination in Angular Component:** In your Angular component, implement logic to manage the current page and items per page. You can also create buttons or links for navigating to the next and previous pages, updating the request's parameters accordingly. 4. **Displaying Data:** Update your component's template to loop through the data received from the paginated API request. Ensure you handle the user interface for pagination controls (e.g., page numbers, next/previous page buttons). 5. **Optional: Creating a Pagination Component:** For reusability, consider creating a dedicated pagination component in Angular that takes the total number of items, items per page, and a method as inputs to update the current page. This component can emit events when the page changes, which your data-fetching component can listen to and fetch the appropriate data. Here's a basic example of what the pagination logic might look like in your component: ```typescript import { Component, OnInit } from '@angular/core'; import { HttpClient } from '@angular/common/http'; @Component({ selector: 'app-data-fetch', templateUrl: './data-fetch.component.html', }) export class DataFetchComponent implements OnInit { posts: any[] = []; currentPage: number = 1; itemsPerPage: number = 10; constructor(private http: HttpClient) {} ngOnInit() { this.fetchData(this.currentPage); } fetchData(page: number) { this.http.get(`api.example.com/posts?page=${page}&limit=${this.itemsPerPage}`) .subscribe((data: any) => { this.posts = data.posts; // Update pagination controls based on response, if necessary }); } goToPage(page: number) { this.currentPage = page; this.fetchData(page); } } ``` In your HTML, you would have controls to navigate through pages and display the data: ```html {{ post.title }} Previous Next ``` Remember, the specifics of how pagination is implemented can vary based on the API you're using and the design of your Angular application. 🔔 Don't forget to subscribe to AyyazTech for more tutorials and tips on Angular. If you need further assistance or have questions, feel free to ask in the comments section below. Happy coding! 🚀
@ajaysaini0629
@ajaysaini0629 6 месяцев назад
Bhai contact no. Dena jaruri hai boht Angular ke liye puchna hai
@IbrahimIbrahim-pe2kq
@IbrahimIbrahim-pe2kq 5 месяцев назад
what about unsubscrbing ?
Далее
Fetching Data in Angular - Do It Correctly
13:50
Просмотров 18 тыс.
What’s new in Angular v18
20:08
Просмотров 118 тыс.
А ВЫ УМЕЕТЕ ПЛАВАТЬ?? #shorts
00:21
Просмотров 1,6 млн
СЕРЕГА ПИРАТ - TEAM SPIRIT
02:37
Просмотров 313 тыс.
Top 6 Most Popular API Architecture Styles
4:21
Просмотров 886 тыс.
How to customize Angular material theme | Angular 17?
17:53
Angular 15 Call Rest API with api-key from Angular
7:31
Deferrable Views - New Feature in Angular 17
15:31
Просмотров 20 тыс.
I tried 8 different Postgres ORMs
9:46
Просмотров 406 тыс.
Angular 10 tutorial #28 call API | HTTP
6:52
Просмотров 114 тыс.
Why aren't you using Fastify? Or Koa? Or NestJS?
9:58