Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

233
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda