1

I have a function in commonservice and i want to call the function by sending the type as argument from another controller and how can i do that,

commonservice :

function getCommonLookupData(type) {
                    var data = angular.fromJson(EmployeeRoles.getItem('lookupData'));
                    var arr = [];
                    if (data)
                        arr = data[type];
                    var arr1 = [];
                    if (arr) {
                        $.each(arr, function (index, val) {
                            arr1.push(val);
                        });
                    }
                    return arr;
                }
            }

contrlrm :

commonService.getCommonLookupData(EmployeeRoles);  

and how can i get the arr of the function,can anyone help please.Thanks.

1
  • i cannot understand, do you want to call service function from different controllers ? Commented Nov 16, 2016 at 15:09

1 Answer 1

1

You should inject the service in the controller like

     app.controller('MyController',function($scope,myServiceName){
         myServiceName.myServiceFunction();
      });
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.