Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.


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.