You can add some generated CSS in angular by doing the following:
angular.element(document).find('head').prepend('<style type="text/css">.my-item { background: blue; }</style>');
To make sure that this isn't injected multiple times, you could create a service CssSvc which can keep track of whether the generated CSS has been injected yet or not.
app.service('CssSvc', function () {
var svc = this;
// keep track if injected
svc.injected = false;
});
Then you can inject the service in to your directive and only run the above code if it has not been run already.
if(!CssSvc.injected) {
angular.element(document).find('head').prepend('<style type="text/css">.my-item { background: blue; }</style>');
CssSvc.injected = true;
}
.cssfile..directivefunction will run once for each directive coincidence in the HTML code, right? (two<my-directive></my-directive>elements will trigger the.directivefunction twice). What I'm asking is if.runor.configwill be ran once, thus allowing me to avoid checking if the styles were already injected.