Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

how to pass form data as parameters along with callback function?

I have an extended question on "calling webservice" on angular js In this tutorial: https://teamtreehouse.com/library/angular-basics/services-in-angular/using-services-to-get-data

you mention about using callback. I am trying to call a http service with some parameters to update the url.

angular.module('todoListApp') .service('dataService', function ($http) { this.getTodos = function (callback) { $http.get('mock/todos.json').then(callback) } });

if I want to update the url based on a dropdown in html. how do i pass the parameter then to the service? I tried the following code but it does not work: angular.module('todoListApp') .service('dataService', function ($http) { this.getTodos = function (callback, newurl) { var url = 'mock/'+newurl+'.json'; $http.get(url).then(callback) } });

any help on this is appiciated.

1 Answer

jared eiseman
jared eiseman
29,023 Points

If I'm understanding your question correctly, what you need to do is pass the 'dataService' as a dependency to the controller in which you are trying to use the url information from. Then from within that controller you call the .getTodos() method so that it has access to the scope in which your 'newurl' is originating.