Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Step 7 - Add rating selected callback

  • Loading branch information...
commit a6bc2fe3807156addb896e8a7962315355296945 1 parent 8905c1f
@shyamseshadri shyamseshadri authored
Showing with 11 additions and 5 deletions.
  1. +2 −4 directives/rating/index.html
  2. +9 −1 directives/rating/rating.js
View
6 directives/rating/index.html
@@ -4,16 +4,14 @@
<title>Rating Directive Demo</title>
<link rel="stylesheet" href="rating.css"/>
</head>
-<body ng-init="rating = 5">
+<body ng-controller="FundooCtrl">
Rating is {{rating}} <br/>
Clickable Rating <br/>
- <div fundoo-rating rating-value="rating" max="10"></div>
+ <div fundoo-rating rating-value="rating" max="10" on-rating-selected="saveRatingToServer(rating)"></div>
<br/>
Readonly rating <br/>
<div fundoo-rating rating-value="rating" max="10" readonly="true"></div>
- <button ng-click="rating = 7">Change rating to 7</button>
-
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.6/angular.min.js"></script>
<script type="text/javascript" src="rating.js"></script>
</body>
View
10 directives/rating/rating.js
@@ -1,4 +1,10 @@
angular.module('FundooDirectiveTutorial', [])
+ .controller('FundooCtrl', function($scope, $window) {
+ $scope.rating = 5;
+ $scope.saveRatingToServer = function(rating) {
+ $window.alert('Rating selected - ' + rating);
+ };
+ })
.directive('fundooRating', function () {
return {
restrict: 'A',
@@ -10,7 +16,8 @@ angular.module('FundooDirectiveTutorial', [])
scope: {
ratingValue: '=',
max: '=',
- readonly: '@'
+ readonly: '@',
+ onRatingSelected: '&'
},
link: function (scope, elem, attrs) {
@@ -26,6 +33,7 @@ angular.module('FundooDirectiveTutorial', [])
return;
}
scope.ratingValue = index + 1;
+ scope.onRatingSelected({rating: index + 1});
};
scope.$watch('ratingValue', function(oldVal, newVal) {
Please sign in to comment.
Something went wrong with that request. Please try again.