Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

232
Views
AngularJS: How to access factory methods from a directive template?

I have a factory that just returns a bunch of config values, something like this:

angular.module('myApp').factory('configService', function (settings) {
   var serviceObj = {};

   serviceObj.showPrices = function () {
      return settings.showPrices;
   }
   return serviceObj;
});

I want to use this showPrices() function to conditionally render price breakdowns in a directive that's used for rendering item details, but the way I have it set up isn't working. My directive looks something like this:

angular.module('myApp').directive('itemSummary', function(configService){
   return {
      templateUrl:'views/item-summary.html',
      restrict: 'E',
      replace: true,
      scope: {
         configService: '&'
      },
      link: function linkFx(scope, attributes){
         function renderPriceBreakdown(){
            console.log(configService.showPrices());
            ...
         }
      }
   }
});

The relevant line of my template looks like this:

<div ng-if="renderPriceBreakdown() && configService.showPrices()">
   ...
</div>

It looks like I have access to configService from inside my directive (.js), since the debug console.log I added in renderPriceBreakdown() is accurately returning my config, but trying to call it from the template is not working. What am I doing wrong? I don't want to account for showPrices() from inside renderPriceBreakdown().

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!