var myApp = angular.module('myApp', []);
myApp.controller('RatingsController', ['$scope', function ($scope) {
$scope.rating = 0;
$scope.artistRatings = {
current: 1, // this is the initial 'current' rating
max: 10 // this is the maximum (ie rating out of 10
};
$scope.venueRatings = {
current: 5, // this is the initial 'current' rating
max: 10 // this is the maximum (ie rating out of 10
};
$scope.artistSelectedRating = function (rating) {
console.log('artistRatings.current', rating);
};
$scope.venueSelectedRating = function (rating) {
console.log('venueRatings.current', rating);
$scope.artistRatings.current= rating; //this is just a test to show that a change in .current results in an immediate update of the graphic
};
}]);
myApp.directive('artistRating', function () {
return {
restrict: 'A', // means directive is added to element as a attribute in snake case eg. "<div artist-rating></div>"
template: // template is added in the element which has the attribute added
'<li ng-repeat="star in stars" class="pref-filter-button" ng-class="star" ng-click="toggle($index)"></li>',
scope: {
ratingValue: '=', // = means two way data binding between $scope and this directives 'isolated scope'
max: '=',
onRatingSelected: '&'
},
link: function (scope, elem, attrs) {
var updateRatings = function () {
scope.stars = [];
for (var i = 0; i < scope.max; i++) {
scope.stars.push({
active: i < scope.ratingValue
});
}
};
scope.toggle = function (index) { // function expression called "toggle" (not a generic ng - ie. a made up...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.