Reputation: 707
Using this Code here: plunkr
How would I write the value on click to the console? It seems as though this will only work in a form submit environment, but I'm hoping I'm wrong.
Note that the rating element is converted into several i elements in a span, and each i has an ng-click applied to it already.
To summarize - When I select a star, spit out the value selected to the console.
Upvotes: 3
Views: 2937
Reputation: 10345
Rating supports ng-click:
<rating value="rate" max="max" readonly="isReadonly"
on-hover="hoveringOver(value)" on-leave="overStar = null"
ng-click="setRating()"></rating>
In your controller, simply add:
$scope.setRating = function() {
alert($scope.rate);
};
Upvotes: 10
Reputation: 2872
Since clicking on an icon changes the value of the bound rating variable, you can just $watch
the change of that scope variable.
eg.
$scope.$watch('rate', function(value) {
console.log(value);
});
http://plnkr.co/edit/bPmbgiI9ryZWSrn1zOfU?p=preview
Upvotes: 2