Dakine83
Dakine83

Reputation: 707

Get value on click from Angular UI Rating Directive

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

Answers (2)

Rich Bennema
Rich Bennema

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

Lucius
Lucius

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

Related Questions