I'm trying to output HTML character Entities as data attributes so that I can display it as I wish using css pseudo elements.
This works when we directly assign the value of attribute in HTML, but doesn't when we bind the value using angular.
Below is the sample code:
var app = angular.module('test', []);
app.config(function($sceProvider) {
// Completely disable SCE. For demonstration purposes only!
// Do not use in new projects.
$sceProvider.enabled(false);
});
app.controller('testCtrl', ['$scope',
function($scope) {
$scope.symbol = "\00a9";
$scope.symbol1 = "©";
}
])
.copy::before {
content: attr(data-symbol);
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="test" ng-controller="testCtrl">
<div class="copy" data-symbol="©">working</div>
<div class="copy" data-symbol="{{symbol}}">not working</div>
<div class="copy" data-symbol="{{symbol1}}">also not working</div>
</div>
As you can see, I tried disabling $sce
entirely as well (for testing purpose).
But that also didn't work.
There will be way too many of these symbols in the application so generating a DOM element for each of them doesn't seem like a good idea.
Is there a way to do this..?
\00a9
is the css equivalent as per brajeshwar.github.io/entities"\u00a9"
seems be unicode sequence for c/c++/java but does work... could you post an answer with a reference where to find these..?!