응답에 따라 동적으로 별표 평점을 표시해야합니다.응답에 따라 동적으로 별표를 표시하는 방법은 무엇입니까?
1에서 5까지의 값을 표시 할 수 있지만 등급이 0이면 빈 별이 표시되지 않습니다.
등급 = 0.4 인 경우 1 개의 별표도 표시됩니다.
내 컨트롤러 :
(function() {
'use strict';
angular
var app = angular
.module('app')
app.directive('starRating', function() {
return {
restrict: 'A',
template: '<ul class="rating">' +
'<li ng-repeat="star in stars" ng-class="star" ng-click="toggle($index)">' +
'\u2605' +
'</li>' +
'</ul>',
scope: {
ratingValue: '=',
max: '='
},
link: function (scope, elem, attrs) {
var updateStars = function() {
scope.stars = [];
for (var i = 0; i < scope.max; i++) {
if(i == 0) {
scope.stars = [];
scope.stars.push({
empty: i = 0
});
} else {
scope.stars.push({
filled: i < scope.ratingValue
});
}
}
};
scope.$watch('ratingValue', function (oldVal, newVal) {
if (newVal) {
updateStars();
}
});
}
}
});
app.controller('Controller', Controller);
Controller.$inject = ['UserService', '$location', '$rootScope', '$scope', 'fileUpload', 'FlashService', '$cookieStore', '$timeout', '$window'];
function Controller(UserService, $location, $rootScope, $scope, fileUpload, FlashService, $cookieStore, $timeout, $window) {
$scope.selectTestSubject = function() {
$scope.rating = 0;
console.log(levels.length);
for(var k=0; k<levels.length; k++) {
var respRating = levels[k].rating;
// var respRating = 1.5;
console.log(respRating);
$scope.ratings = [{
current: respRating,
max: 5
}];
if(respRating == 0) {
$scope.defaultRating = true;
} else {
$scope.defaultRating = false;
}
}
}
}
})();
내 HTML 페이지 : 솔루션과
<div><span ng-repeat="rating in ratings">
<div star-rating rating-value="rating.current" max="rating.max"></div>
</span>
</div>
'등급이 0이면 비어있는 별이 표시되지 않습니다. '등급이 0 인 경우 표시 할 시작 횟수는 몇 개입니까? –
for (var i = 0; i
gyc
최대 값 = 5 즉, 별표 없음 = 5를 사용하고 있습니다. 등급 = 0이면 별표가 표시되지 않는 대신 5 개의 별표가 표시되어야합니다. @ Raman Sahasi – kalai