user3718908x100
user3718908x100

Reputation: 8509

Pass controller method to directive with isolated scope

Hello i have a controller that uses various services like $http, $scope, $window. Now i have also a directive with an isolated scope. I am aware i can easily pass a controller method to a directive but i would like to know about the services. Supposing the method in my controller uses both the $http and $window service or some other custom service when i pass it to my directive are those services passed along with it? If not then how can i pass those services along with the method to my directive.

Upvotes: 0

Views: 46

Answers (1)

buzzsaw
buzzsaw

Reputation: 1486

The services you wish to use need to be injected into your directive.

.directive('directiveName', ["$injectedService", "$window", "$http", function($injectedService, $window, $http) {
  return {
    ... your directive code here ...
  };
}]);

You can find information about directives in the angular docs. https://docs.angularjs.org/guide/directive

Upvotes: 2

Related Questions