Тёмный
No video :(

Angular 2 http service tutorial 

kudvenkat
Подписаться 832 тыс.
Просмотров 212 тыс.
50% 1

Tags
angular 2 injectable example
angular 2 http calls
angular 2 http cors
angular 2 http example
angular 2 http observables
angular 2 http request
angular 2 http rest example
angular 2 http simple example
angular 2 http tutorial
angular 2 http typescript
angular observable example
angular http cross origin request
angular cross-origin request blocked
angular 2 cross domain request
Text version of the video
csharp-video-tu...
Healthy diet is very important both for the body and mind. If you like Aarvi Kitchen recipes, please support by sharing, subscribing and liking our RU-vid channel. Hope you can help.
/ @aarvikitchen5572
Slides
csharp-video-tu...
Angular 2 Tutorial playlist
• Angular 2 tutorial for...
Angular 2 Text articles and slides
csharp-video-tu...
All Dot Net and SQL Server Tutorials in English
www.youtube.co...
All Dot Net and SQL Server Tutorials in Arabic
/ kudvenkatarabic
In this video we will discuss
1. How to call ASP.NET Web API service using Angular 2 http service. Though this example demonstrates calling ASP.NET Web API service, we can use this same approach to call any web service built using any server side technology.
2. We will also briefly discuss Observable pattern
In our previous video we have created ASP.NET EmployeeWebAPIService. Here are the steps to call the Web API service using the Angular builtin http service.
Step 1 - Import the angular HTTP module : The first step is to import HttpModule which is present in a separate javascript file - @angular/http. After the HttpModule is imported, include it in the imports array of the NgModule() decorator of our root module "AppModule" which is in "app.module.ts" file. With this change we can now start using the angular built-in http service throught our application to access web services over HTTP.
import { HttpModule } from '@angular/http';
@NgModule({
imports: [
HttpModule],
declarations: [
],
bootstrap: [AppComponent]
})
export class AppModule { }
Step 2 - Modify angular EmployeeService to issue a GET request using the builtin http service :
1. The angular EmployeeService is in employee.service.ts file.
2. Use the EmployeeService class constructor to inject Angular Http service. The injected http service can then be used anywhere in this class to call a web service over http.
3. Since this Angular EmployeeService class has an injected dependency, @Injectable() decorator is required on this class. If there are no injectable dependencies then we may omit the @Injectable() decorator, but angular strongly recomends to use the @Injectable() decorator irrespective of there are injectible dependencies or not for consistency and future proof.
4. Notice in the getEmployees() method, we are using the get() method of the angular http service to issue a get request over http.
5. If you right click on get() method and go to it's definition you will notice that this method return Observable[Response].
6. Observable[Response] is not that useful to us, so we have set the return type of getEmployees() method to Observable[IEmployee[]]
7. To convert Observable[Response] to Observable[IEmployee[]] we are using the map operator provided by rxjs.
At the moment, we are not handling exceptions. We will discuss how to handle exceptions in our upcoming videos.
What is an Observable
1. Observable is an asynchronous pattern. In the Observable pattern we have an Observable and an Observer. Observer observes the Observable. In many implementations an Observer is also called as a Subscriber.
2. An Observable can have many Observers (also called Subscribers).
3. Observable emits items or notifications over time to which an Observer (also called Subscriber) can subscribe.
4. When a subscriber subscribes to an Observable, the subscriber also specifies a callback function.
5. This subscriber callback function is notified as and when the Observable emits items or notifications.
6. Within this callback function we write code to handle data itmes or notifications received from the Observable.
Step 3 - Subscribe to the Observable returned by angular EmployeeService : EmployeeListComponent needs the employees data returned by the service. So in the ngOnInit() method of "employeeList.component.ts" use the subscribe method as shown below.
ngOnInit() {
this._employeeService.getEmployees()
.subscribe(employeesData =] this.employees = employeesData);
}

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

 

26 авг 2024

Поделиться:

Ссылка:

Скачать:

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

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 92   
@prateekbhardwaj9943
@prateekbhardwaj9943 6 лет назад
this is the world's best tutorial of angular 2. I have checked various resources none can beat this channel. every topic is explained in a very easy to understand manner. learned so many things like web API, c# =, MVC. etc. from kudvenkat channel. thank you.
@sumanadas9095
@sumanadas9095 5 лет назад
I dont comment on videos how much i love or hate...but cant stop commenting here..your videos are incredibly informative and i always learn something new watching your videos. I became your fan... its just awsome watching your videis..not get bored while learning rather you made it interesting. Thanks a ton.
@Csharp-video-tutorialsBlogspot
Thank you Sumana. It's an honour. Very glad you found our videos useful. You can find all our Angular courses at the following link. www.pragimtech.com/angular_tutorial_for_beginners.aspx
@vichitraanand673
@vichitraanand673 Год назад
You are my mentor, guru. I am software developer because of you kudvenkat sir.
@tusharkukreti7448
@tusharkukreti7448 7 лет назад
This is superb!! Great Explanation. Thank you so much
@rogersmith7475
@rogersmith7475 7 лет назад
thank you so much for demonstrating Angular with .Net Web API and SQL Server on the back end...great full stack demonstration...front... business logic... database
@sonaighosh
@sonaighosh 5 лет назад
Best Angular tutorial i ever came across
@maksymkulaistra2854
@maksymkulaistra2854 5 лет назад
you are the best. I do like your videos
@tusharkukreti7448
@tusharkukreti7448 7 лет назад
Hi can you also please explain how to post or put data using angular 2?
@manojkaselakimku5071
@manojkaselakimku5071 5 лет назад
Such a good teacher and hard efforts you are a god
@raphaelbernard7954
@raphaelbernard7954 6 лет назад
Thank you Vankat for these wonderful tutorials
@alen1024
@alen1024 5 лет назад
you angular tutorial is best. thanks.
@AvdhutVaidya84
@AvdhutVaidya84 4 года назад
Please mark in your title as "Observable" too.. i was searching for Observable before watchfully seeing the playlist and deciding where i could find the explanation of Observable
@jenithjana5178
@jenithjana5178 4 года назад
Found it useful! Thanks :)
@TrungNguyen-vt1nc
@TrungNguyen-vt1nc 5 лет назад
as usual Supper!!!
@sanjaykumawat5715
@sanjaykumawat5715 4 года назад
Excellent tutorial..
@DecentProgrammer
@DecentProgrammer 3 года назад
nice video
@nguyenhohai88
@nguyenhohai88 6 лет назад
excellent tutorial. Thanks
@narendrakundla645
@narendrakundla645 6 лет назад
hello Venkat, Iam a good fan of you. your angular 2+ tutorials are awesome. can u provide git link of angular 2+..?
@amolkhedkar9026
@amolkhedkar9026 4 года назад
Hello sir , at first would like to say thanks a ton to you. videos you make are really really very helpful and made careers of lot many people. sir, while going through your angular video series , in http service video on which i am making this comment i faced one problem. i have did the same way you did in to call the web api in employee service class but there is an error with map operator.
@sreenivasulugattu9661
@sreenivasulugattu9661 6 лет назад
Hello Venkat garu.. Thanks for your videos.. I am getting small error - "map does not exist on type Observable".
@aigerimiskakova963
@aigerimiskakova963 4 года назад
I have the same error. Could you solve this problem?
@vishalshira7398
@vishalshira7398 6 лет назад
Hello Sir, I am getting below error after implementing above code. Please share your inputs. ERROR in ./src/app/employee-list/employee.service.ts Module not found: Error: Can't resolve 'rxjs/add/operators/map' in 'E:\AngularDemo\src\app\employee-list' i 「wdm」: Failed to compile. ERROR in src/app/employee-list/employee.service.ts(19,16): error TS2339: Property 'map' does not exist on type 'Observable'.
@tubebedex
@tubebedex 3 года назад
Is httpmodule deprecated?
@sangramkesaridash9225
@sangramkesaridash9225 6 лет назад
Awesome explanation...
@chix_the_viper2823
@chix_the_viper2823 2 года назад
Sir only array index is fetching not other data coming from database ,like name gender etc, and also there is no any error in console too.
@pitchaipillai519
@pitchaipillai519 7 лет назад
thank you sir.. expecting more videos..
@SasukeUchiha723
@SasukeUchiha723 5 лет назад
what if I have different ports since i use angular on vs code and api on vs 2018?
@garth-baker-blog
@garth-baker-blog 5 лет назад
Ok so I'm also still learning but maybe I can help u, what I have found is if you run your Angular with from your CLI. Run the command -> "dotnet run" inside your angular project not "ng serve". I think this should get your project running with your asp dotnet project (I think -> try it and see.) Also in the video it shows that you need to Import angular HTTP. By Importing HTTP I think you should be able to run your API's on any port I think as long as your path is correct.
@siddhu004
@siddhu004 5 лет назад
why wasnt providers used here when injecting claas
@garth-baker-blog
@garth-baker-blog 5 лет назад
Thank you for this video super helpful. :)
@shivbhaktadnyaneshwa
@shivbhaktadnyaneshwa 6 лет назад
In given tutorial,When we are loading employee data from database,It looks like performance issue.It takes 4-5 second just to load 6 record.Is there any way to avoid such a impact.
@Prasadrkmca
@Prasadrkmca 3 года назад
add index
@VenuGopal-qb8bw
@VenuGopal-qb8bw 5 лет назад
thanq
@raqibul1000
@raqibul1000 7 лет назад
Thanks a Billions.
@siddharthreja
@siddharthreja 4 года назад
Thank You (:
@raphaelbernard7954
@raphaelbernard7954 6 лет назад
Vankat can you help with this issue TypeError: _co.getTotalMaleEmployeesCount is not a function? I cannot find this underscore getTotal... its referring to? Curiously when I remove all references to gender controls it displays the employee list?
@AmadasChannel
@AmadasChannel 7 лет назад
Can you please include videos on how angular can be used with mvc
@kyleabens
@kyleabens 6 лет назад
How did you convert the xml into json? I have a Web API that is very similar and I get the error 'Unexpected token < in JSON at position 0' . I can't find an answer anywhere. Hope you can help
@RachitJain4U
@RachitJain4U 5 лет назад
Awesome :) Thanks :)
@rajeshbattula6356
@rajeshbattula6356 6 лет назад
Hi sir !!!. This videos are very useful to any new learner. Can you please upload video for CRUD operations in html table with edit button taking us to form with values already binded to form elements?
@avinash23525
@avinash23525 4 года назад
How about security, calling web api in this way
@atmansangeethamani5373
@atmansangeethamani5373 6 лет назад
is there any way to do this http.get request in visual studio code, if so how to handle cross origin issue. I am using vs code.
@pranaydeshpande2904
@pranaydeshpande2904 5 лет назад
Hi can you also please explain how to consume wcf service in angular 2 please..
@112raviverma
@112raviverma 6 лет назад
As shown is this video it looks like the loading time is way too much. Does this takes this much time in actual environment also ?
@MJAlwajeeh
@MJAlwajeeh 6 лет назад
No, it does not. It's only taking time because hes' rebuilding the project, so on first call, it has to JIT compile and it takes longer than normal. On subsequent calls, or in a real production environment, the code would already be ready to call (and you can use a technique to warm it up so your first caller doesn't have to pay the warm up price). Cheers, MJ
@amiratarek7645
@amiratarek7645 5 лет назад
Hi after i add ngIf in the html it give me same error of length undefined
@kranti263
@kranti263 6 лет назад
very nice video sir , can you suggest me what is best way to use chat app in anuglar 2 application like chat of facebook web version . can we do it using signalR/NodeJs or need any 3rd party tools.
@ravichandranaikanavre1561
@ravichandranaikanavre1561 6 лет назад
Hi sir, is there any video for Post Data using angular2 with webapi 2?
@excitingmonkey3970
@excitingmonkey3970 7 лет назад
Thanks
@srinivasvarma6543
@srinivasvarma6543 7 лет назад
Hi sir can you please make a video of how to send post request with body parameters to Webapi post method and similarly put and delete methods.
@ycce17
@ycce17 6 лет назад
Hi, With post method you can sent the Data to backend. Below is the sample. Http.post(url: string, body: any, options?: RequestOptionsArgs) This will return you Observable .
@AbhishekKumar-dk7pr
@AbhishekKumar-dk7pr 6 лет назад
Hi Can you please make a video on to make soap API request in Angular.
@yalairfan7252
@yalairfan7252 6 лет назад
I am trying same exmpl with Spring rest api but emplyee obj is showing undefined...!! and i got result in the form of json when i run that rest project in browser directly.. please give solution
@ChandanKumar-ik8pf
@ChandanKumar-ik8pf 7 лет назад
Excellent explanation. One minor issue - I had applied *ngIf="employees" still I am getting length error. Please suggest why this is happening?
@miteshvora
@miteshvora 7 лет назад
Had the same issue, its the issue in chrome due to cors implementation in google chrome and happens only in case of localhost, you can solve this by downloading chrome extension from chrome.google.com/webstore/detail/allow-control-allow-origi/nlfbmbojpeacfghkpbjhddihlkkiljbi, be sure to turn it off when not using the app, you can read more at stackoverflow.com/questions/28547288/no-access-control-allow-origin-header-is-present-on-the-requested-resource-err.
@ChandanKumar-ik8pf
@ChandanKumar-ik8pf 7 лет назад
mitesh vora thanks for reply, I have tested with mozila browser working perfectly. Will try with chrome as you suggested.
@rafakoscinski5319
@rafakoscinski5319 7 лет назад
for me did not work, I'm still getting the error. What strange is that on the html file the ngIf directive is not showing where as other one is, any other ideas? How is it possible that on the tutorial the lecturer does not need to setup anything...I hate this kind of bumps on the road...so frustrating, By the way on FF for me it does not work also EDIT: Works fine on IE lol, for firefox needs to be an addon downloaded also it's called cors everywhere but for chrome none of this addons work for me. Not even with chrome --disable web security option. I'm still getting the undefined error
@rafakoscinski5319
@rafakoscinski5319 7 лет назад
Writing a new post just for clarity. I've managed to fix this. 1. Run the web API service and put a break point see if the request is even going to your api. I did not had it turnd on. Basically thing that are turned on work better then turned off ;) 2. Disable all cache functionality in your chrome (that's why I did not see the ng if, the bloody cache in chrome). There is one in network tab after hitting F12, and the other one in developer setings called Disable cache (while DevTools is open (after hiting F12, hit F1 and look for that option) 3. Add the web.config settings that is mentiioned in the tutorial. I believe not adding the addons to web browser but the cache things are more important. I've deleted the addons and everything and I'm keeping the web api running, then it works fine. When I don't do it...I get ERR_CONNECTION_REFUSED...nothing helpes not even adding the Miscrosoft...WebApi.Cors stackoverflow.com/questions/25327711/mvc-webapi-2-with-angularjs-err-connection-refused (second answer) So maybe my conclusions will help somebody struggling with the issues with this tutorial
@ChandanKumar-ik8pf
@ChandanKumar-ik8pf 7 лет назад
I found one disabled cache options. - I marked it disabled, its now working without installing any plugin. Thanks Rafal.
@dropyghost
@dropyghost 7 лет назад
at 17:30 he said talk about this in another video, but I cant understand what video is. Can anyone tell me? I understand 14 or 15 but not the series.
@MohanrajPeriasamy
@MohanrajPeriasamy 7 лет назад
He is talking about WebAPI... videos part 14 and 15..there he discussed cross origin related
@MJAlwajeeh
@MJAlwajeeh 6 лет назад
He's referring to his other tutorial series where he covers the cross domain topic with ASP .NET Web API. Here's the link to that series (ASP .NET Web API tutorial for beginners): ru-vid.com/group/PL6n9fhu94yhW7yoUOGNOfHurUE6bpOO2b Video 14 in that series (Calling ASP NET Web API service in a cross domain using jQuery ajax): ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-WKZLVqwpoiE.html Video 15 in that series (Cross origin resource sharing ASP NET Web API): ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-nsnuIZX1C9A.html
@prashantjakulwar2129
@prashantjakulwar2129 6 лет назад
sir im getting the .map error?
@adir191
@adir191 7 лет назад
Hey, how did you create the xml file? is there any online tool to do that?
@TheSilent333
@TheSilent333 7 лет назад
That XML file was just the result of the WebAPI method call. See the previous video in the series. :)
@rogersmith7475
@rogersmith7475 6 лет назад
when deploying to Azure app services...do i need to change the baseURL for the API controller location from "localhost:50327" to something else in order for it to work on Azure..or just keep it as is and Azure will change it for us...
@MJAlwajeeh
@MJAlwajeeh 6 лет назад
You'll need to change the baseURL when deployed to Azure. The domain "localhost" is only applicable when you're running web apps on your local dev environment. You'll need to find out what the domain is for your web app when you deploy to Azure, and use that instead.
@santhoshkumar-sf4bc
@santhoshkumar-sf4bc 4 года назад
Sir, how to make SEARCH table data from search INPUT BOX in angular
@abidalisidd
@abidalisidd 6 лет назад
Why we need Observable, why not just return array of Employee, Don't we have any function like get to return our API response. Just like Jquery Get function. Our Employee service is just need a array of Employee and you are returning an Observable, why ? .We should reduce complexity but we keep increasing this.
@Csharp-video-tutorialsBlogspot
Hello Abid - Observables sound a bit difficult, but once you understand how to use them, they are not that difficult. Obervables are similar to promises and callbacks we use with jQuery get. Observables are much more powerful and provides lot of powerful functionality which is otherwise very difficult to achieve the same with promises. We will discuss some of the useful and powerful features of Observable in our upcoming videos in Angular CRUD tutorial. Hope this answers your question. I have included the link to Angular CRUD tutorial below if you want to check it out. ru-vid.com/group/PL6n9fhu94yhXwcl3a6rIfAI7QmGYIkfK5
@varunsharma10286
@varunsharma10286 6 лет назад
Hi sir, i am getting 'undefined' when i try to get the response from webApi using Observables.i have implement CORS also in webApi config file. Please reply how to fix that issue ?
@tumblevids
@tumblevids 4 года назад
hi even i am getting undefined. Did you get the answer for that?
@richashukla8828
@richashukla8828 6 лет назад
Hi , Thanks for the awesome tutorial. This tutorial helps me a lot to understand the Angular 2 framework. But I am stuck on one point .Please help me out. while Importing the Observable from the rxjs library ,I am getting the error "Module '"node_modules/rxjs/Observable"' has no exported member 'Observable'." because of this the map operator is also showing the error Property 'map' does not exist on type 'Observable'. I have google out the error but not get the specific solution . PFB the code : import { Injectable } from '@angular/core'; import { IEmployee } from './employee'; import { Http, Response } from '@angular/http'; import { Observable } from 'rxjs/Observable'; import 'rxjs/add/operator/map'; @Injectable() export class EmployeeService { private _url : string = 'apiData/employeedata.json' constructor(private _http: Http) { } getEmployees(): Observable { return this._http.get(this._url) .map((response: Response) => response.json()); } } Any help will be appreciated !! thanks in advance . Apologies for grammatical mistakes.
@Sheikhstyle
@Sheikhstyle 7 лет назад
With http.post I'm getting this error "Failed to load resource: the server responded with a status of 405 (Method Not Allowed)" Can anybody help to solve it? btw I've tried Cors package but it didn't work.
@ycce17
@ycce17 6 лет назад
it seems like you didn't config your request body to JSON type or the type which your server accept
@tassawaryounas4781
@tassawaryounas4781 6 лет назад
Yaar Http service Video ma aadhi files ka pata hi nahi lag raha 6 7 files haan sirf 3 4 btaen haan
@furqans.mahmoud4511
@furqans.mahmoud4511 6 лет назад
+1
@systemsatyaki
@systemsatyaki 7 лет назад
Sir, I have a little observation here that is , you are using _http.get("localhost:31324/api/employees") in EmployeeService, but if my WEB API is running in different server then I should write this code _http.get("www.example.com/api/employees") right ? if in future I do host my API another server for example "www.example2017.com/api/employees" then, should replace this API call manually _http.get("www.example2017.com/api/employees") instead of _http.get("www.example.com/api/employees") entire the application or do you have any other way ? please clarify the same or refer me a video.
@ycce17
@ycce17 6 лет назад
yes.. You need to give your URL address while making service call. It is always possible that the API link changes with time or by need.
@prabhukadode723
@prabhukadode723 7 лет назад
But http service in angular 2 has been ,made more complicated with all stupid concepts like observable and bla bla.. they could have made it easy...
@TellaTrix
@TellaTrix 3 года назад
This video screwed developer life
@nitashadas8786
@nitashadas8786 6 лет назад
what is that IEmployee , you imported in ts file
@Csharp-video-tutorialsBlogspot
IEmployee is the interface. What is an interface and it's benefits are discussed in Part 23. Here is the link to that video. ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-Be3-ZWtC1Lo.html Here is the link to the text version of the video csharp-video-tutorials.blogspot.com/2017/08/angular-2-http-service-tutorial.html Here is the link to Angular 2 Playlist ru-vid.com/group/PL6n9fhu94yhWqGD8BuKuX-VTKqlNBj-m6
@jayababuthumati6297
@jayababuthumati6297 7 лет назад
Boss jsut think about NodeJs also, you only can teach better
@subhashnambiar9
@subhashnambiar9 7 лет назад
What you mean? He doing a great job. He know how to teach very well. What you know stupid.
@urielii0117
@urielii0117 5 лет назад
For those who encountered the error: "map does not exist on type Observable", implement the solution provided by the following link will solve the issue. It is all because we are using an Angular version greater than 4. medium.com/coding-snippets/rxjs-5-5-property-map-does-not-exist-on-type-observable-e825129c2068 It worked for me. I do hope it will also work for you. If it doesn't, you may try the following solution. // Begining of the solution description Add the below command in your *.service.ts file" import { map } from "rxjs/operators"; **********************************************Example**Below************************************** getPosts(){ this.http.get('jsonplaceholder.typicode.com/posts') .pipe(map(res => res.json())); } } I am using windows 10; angular6 with typescript V 2.3.4.0 // End of the solution description I didn't try it by myself, but it seems fine. I do hope this solution will eventually help you.
Далее
Angular 2 http error handling
7:55
Просмотров 94 тыс.
Angular 2 route parameters
23:10
Просмотров 92 тыс.
Музыкальные пародии
00:28
Просмотров 22 тыс.
What is Observable | Observables | Angular 12+
14:16
Просмотров 152 тыс.
Angular services tutorial
13:52
Просмотров 170 тыс.
Angular component output properties
16:56
Просмотров 154 тыс.
Angular 2 routing tutorial
17:38
Просмотров 129 тыс.
Promises in angular 2 example
8:45
Просмотров 95 тыс.
Using Bootstrap with Angular 2
8:45
Просмотров 85 тыс.
Angular promises vs observables
9:47
Просмотров 194 тыс.
Музыкальные пародии
00:28
Просмотров 22 тыс.