ng-src is a great directive, it allows you to hide de src request for an
image until angular has fully loaded. I am having a bad time trying to
figure out how can I reproduce this directive's behavior in my own
directive in order to do the same but for loading CSS.
Here is my code so far:
.directive('xStyle',
function()
{
return {
restrict: 'E',
replace: true,
scope: { xUrl : '=' },
template:'<style>' +
' @import url("{{xUrl}}")' +
'</style>',
};
}
);
very simple (it seems), the problem is that it doesn't work as expected,
since there is a double request being made to the server from the app
(ionic bundle, but angular 1.28 after all), the first request looks
something like this:
http://serverAddress/{{xUrl}}
(well actually url encoded, I put it like this to increase the readability
to better illustrate the issue. Then, after the values are loaded (binding
the template to the directive parameters), a second request is issued to
the server, this time with the right url and therefore getting the proper
css and all works well.
What I want is get rid of the first GET request to the server that the
browser does, it seems to me that by compiling somehow this code in an
earlier phase could probably render the compiled code with the actual
params and avoid those milliseconds in which the uncompiled version is
rendered and the wrong request is generated. The problem is that after
reading the angular js documentation for directive I know there is a
compile and link phase but I have no clue on how to approach this.
Any ideas?
Thanks for your kind help.
--
You received this message because you are subscribed to the Google Groups
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.