Is there a way to access data shared in a service within a directive? Let's say we have a directive called resultsDirective
, and a service named dataService
. How can we retrieve a variable from the service within the directive?
angular.module("someModule").service("dataService", function() {
var shareVariable;
})
angular.module("someModule").directive("resultsDirective" , ["dataService", function(dataService) {
return {
restrict: ,
scope: ,
link: function() {}
//Apologies for the lack of implementation, just a basic structure provided
}
}])
If we wanted to output the value of shareVariable
from the resultsDirective
using console.log
, how would we go about accessing this data in Angular?