Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

231
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda