avi
avi

Reputation: 29

How to pass parameters from controller to service

My goal is to create an http post method in the service that gets the following parameters from the controller: id, firstname,lastname,email,phonenumber ,in the controller:

function updateClient(client){
    var clientId=client.id;
    var firstName=$("#clientFirstName");
    var lastName=$("#clientLastName");
    var email=$("#clientEmail");
    var phoneNumber=$("#clientPhoneNumber");
    updateClient.postClient().then(function(data) {

    });
}

and in the service:

  testProjectApp.factory('updateClient', function($http, $q) {
   return { ...

Upvotes: 1

Views: 43

Answers (1)

Ufuk Hacıoğulları
Ufuk Hacıoğulları

Reputation: 38468

You need to define the function in the object you are returning:

testProjectApp.factory('updateClient', function($http, $q) {
   return { 
       postClient : function(firstName, lastName) {
           //do stuff
       }
   }
});

Upvotes: 1

Related Questions