Skip to content

Instantly share code, notes, and snippets.

@EmmanuelDemey
Created November 24, 2014 13:07
Show Gist options
  • Select an option

  • Save EmmanuelDemey/b8456da17b466b4ec48a to your computer and use it in GitHub Desktop.

Select an option

Save EmmanuelDemey/b8456da17b466b4ec48a to your computer and use it in GitHub Desktop.
Slide 124 - Using the scope property
<div data-ng-app="app">
<div class='html-content'><div data-ng-controller="ProductRatingCtrl">
<star-rating data-value="{{productMarkCss}}">2 comments</star-rating>
Mark:
<select data-ng-options="mark for mark in marks" data-ng-model="productMark" />
</div></div></div>
angular.module('app',[])
.directive('starRating', function () {
return {
restrict: 'E',
transclude: true,
scope: {
"value": "@"
},
template: "<p data-ng-class=\"value\" data-ng-transclude></p>"
};
});
var ProductRatingCtrl = function($scope) {
$scope.marks = [ "one", "two", "three", "four", "five" ];
// Default CSS Class for the product.
$scope.productMark = "three";
$scope.$watch('productMark', function() {
$scope.productMarkCss = "rating " + $scope.productMark;
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment