I would like to use the following jQuery from angular:
jQuery.prototype.stars = function() {
return $(this).each(function() {
var val = parseFloat($(this).html());
var size = Math.max(0, (Math.min(5, val))) * 16;
var $span = $('<span />').width(size);
$(this).html($span);
});
}
$(function() {
$('span.stars').stars();
});
The code is copied from here: Turn a number into star rating display using jQuery and CSS
It seems it should be added in a directive, something like this:
link: function ($scope, elem, attrs) {
angular.element(document).ready(function () {
$('span.stars').stars()
...
but I am not sure how to rewrite the function stars() jQuery has been extended with (jQuery.prototype.stars). Thanks so much for your help!