It's not easy for me to try to dynamically populate the content value for the :before
pseudo-element. I found out that this is possible in earlier versions of AngularJS in another question above here , creating an additional data attribute for the element with before
-pseudo on it, and then read that value using attr()
in CSS.
It seems to work just fine when using a simple string as a value:
// CSS .test:before { content: attr(data-before); } // Template <div class="test" data-before="before text goes here"> <h2>Hello {{name}}</h2> </div>
But when I try to populate data-before with such interpolation, I get an error message:
// CSS .test:before { content: attr(data-before); } // Template <div class="test" data-before="{{name}}"> <h2>Hello {{name}}</h2> </div>
What am I missing here? Error Created:
Error: Template parse errors: Can't bind to 'before' since it isn't a known property of 'div'.
Here's a non-working version in plunker: http://plnkr.co/edit/HwVp9jlsx6uKfoRduxWu
source share