I have an attribute aria-valuenow which is being modified by jQuery in the rateit star rating jQuery plugin when a user does the rating or changes that rating when submitting a review form.
Following is the html snippet I use to display the stars of the plugin.
<div class="review">
<input type="range" value="0" step="0.25" id="backing4">
<div class="rateit" plugin-rate-it="{backingfld: '#backing4', resetable: 'true', ispreset: 'false', min: 0, max: 5}" data-rateit-backingfld="#backing4" data-rateit-resetable="false" data-rateit-ispreset="true" data-rateit-min="0" data-rateit-max="5"></div>
</div>
In the above html plugin-rate-it is a directive I have that initialized the plugin, otherwise the stars are not displayed. Below is the code for the directive.
myApp.directive('pluginRateIt', function() {
return {
restrict: 'A',
link: function(scope, element, attrs) {
$(element).rateit(scope.$eval(attrs.pluginRateIt));
}
};
});
Now, below is the html that is rendered when the page loads for the html code above. I've got it from the page's source code.
<div class="review">
<input type="range" value="0" step="0.25" id="backing4" class="ng-pristine ng-valid" style="display: none;">
<div class="rateit" plugin-rate-it="{backingfld: '#backing4', resetable: 'true', ispreset: 'false', min: 0, max: 5}" data-rateit-backingfld="#backing4" data-rateit-resetable="false" data-rateit-ispreset="true" data-rateit-min="0" data-rateit-max="5">
<button id="rateit-reset-2" data-role="none" class="rateit-reset" aria-label="reset rating" aria-controls="rateit-range-2" style="display: none;"></button>
<div id="rateit-range-2" class="rateit-range" tabindex="0" role="slider" aria-label="rating" aria-owns="rateit-reset-2" aria-valuemin="0" aria-valuemax="5" aria-valuenow="0" aria-readonly="false" style="width: 80px; height: 16px;">
<div class="rateit-selected rateit-preset" style="height: 16px; width: 0px; display: block;"></div>
<div class="rateit-hover" style="height: 16px; display: none; width: 0px;">
</div>
</div>
</div>
</div>
So, the only attribute that changes when the user does the rating or changes the rating is the aria-valuenow attribute.
Could somebody help me understand that how could I watch for the changes in the value of the aria-valuenow attribute, so that I could capture that value in the ng-model of my review form and submit it.
aria-valuenowis displayed on the html source of the page only after the page has been loaded. The RateIt jQuery plugin seems to be doing its thing to do that. I could only assign it its initial value through thevalueattribute in the<input type="range" value="0" step="0.25" id="backing4">element.valueattribute in theinputtag to something in scope, for example,value="{{stars}}", to keep in sync with the value ofaria-valuenowattribute, thinking that it would give me thearia-valuenowattribute's value in$scopein my controller, I found out that if I do that then thearia-valuenowis set to 50 by the plugin for some reasons.