Skip to content

Instantly share code, notes, and snippets.

@franklinjavier
Created January 23, 2016 15:31
Show Gist options
  • Save franklinjavier/39e24eb4aa880e732e53 to your computer and use it in GitHub Desktop.
Save franklinjavier/39e24eb4aa880e732e53 to your computer and use it in GitHub Desktop.
Rating in angularjs
angular.module('plunker', [])
.directive('rating', function() {
return {
scope: {
rate: '=',
onUpdate: '&'
},
templateUrl: 'rating.html',
link: function(scope, element, attrs) {
scope.range = [1,2,3,4,5];
scope.update = function(value) {
scope.rate = value;
if (scope.onUpdate) {
scope.onUpdate({value: value});
}
};
}
};
})
.controller('MainCtrl', function($scope) {
$scope.rate = 2;
$scope.onUpdate = function(value) {
console.log('here');
$scope.customRate = value / 5;
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment