Is there a more efficient design pattern to ensure that angular directives are rendered according to globally specified parameters? For instance, if I have a factory named "Settings" with the value "directiveColor: red", every time my directive is linked it checks for the color setting in Settings before rendering. While this currently works fine, it seems inefficient when I have multiple elements on the page each asking for the same settings repeatedly. What would you suggest?
UPDATE
Factory
app.factory('Settings', function() {
var data = {
//...
directiveColor: red //set by user
}
//...
GetSettings : function () {return data}
}
Directive
app.directive('wdMyDirective', ['Settings', function(Settings) {
return {
restrict: 'E',
link: function(scope, elem, attr) {
scope.data = {
//...
color: Settings.GetSettings().directiveColor
};
};
}]);
//later "color" used in template through the scope
Although the current setup works fine, I'm concerned about the efficiency of having each directive request settings every time it renders (especially with many instances on the page using ngRepeat). Do you think there might be a better approach?