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().