jay.pepper jay.pepper - 1 year ago 97
Ajax Question

how to use angular to get data from a web endpoint?

I need to use angular to get data from a web endpoint and then it needs to show it to the user. The Environment should be configured using bower, using grunt as a task manager.

I already have bower, angular and boostrap installed, the layout of the page is done. The question is, how do I fetch the data from that endpoint to show it? (it's basically a list with id's and names)

Thank you

Answer Source

Try to use angular's $http service to retrieve data from endpoint. https://docs.angularjs.org/api/ng/service/$http#get

After that in callback function you will be able to use and save data from your endpoint into your controller.

And just render it as usual.


$http({method: 'GET', url: 'your url as a string'}).
    then(function(response) {
       // here your response goes. Use it.
       // in your case - your data will be in response.data
    }, function(response) {
       // here is the error if requset failed.
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download