Rendering a Star Rating System using angularjs

后端 未结 7 1165
执笔经年
执笔经年 2020-12-08 17:54

My app is in this Fiddle I need to render a star rating system dynamically from a http service, where the current stars and maximum stars can vary with each case.

Is

7条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-08 18:23

    hmc.starRating.js

    angular.module('starRatings',[]).directive('starRating', function () {
            return {
                restrict: 'A',
                template: '
      ' + '
    • ' + '\u2605' + '
    • ' + '
    ', scope: { ratingValue: '=', max: '=' }, link: function (scope, elem, attrs) { console.log(scope.ratingValue); function buildStars(){ scope.stars = []; for (var i = 0; i < scope.max; i++) { scope.stars.push({ filled: i < scope.ratingValue }); } } buildStars(); scope.$watch('ratingValue',function(oldVal, newVal){ if(oldVal !== newVal){ buildStars(); } }) } } }); **app.js** var app = angular.module('app', ['ui.bootstrap', 'starRatings']); **indix.html**
    .rating { color: #a9a9a9; margin: 0 !important; padding: 0 !important; } ul.rating { display: inline-block !important; } .rating li { list-style-type: none !important; display: inline-block !important; padding: 1px !important; text-align: center !important; font-weight: bold !important; cursor: pointer !important; width: 13px !important; color: #ccc !important; font-size: 16px !important; } .rating .filled { color: #ff6131 !important; width: 13px !important; }

提交回复
热议问题