Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/454.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 将排名编号更改为开始_Javascript_Angularjs_Ranking - Fatal编程技术网

Javascript 将排名编号更改为开始

Javascript 将排名编号更改为开始,javascript,angularjs,ranking,Javascript,Angularjs,Ranking,我需要把我的排名号改成明星 我使用了以下代码: 但是当排名为零时,我根本看不到星星 在本例中,当 $scope.ratings = [{ current: 0, max: 10 }, { current: 3, max: 5 }]; 我怎样才能改变它 这就是我想要改变的 var updateStars = function () { scope.stars = []; v

我需要把我的排名号改成明星 我使用了以下代码:

但是当排名为零时,我根本看不到星星 在本例中,当

$scope.ratings = [{
    current: 0,
    max: 10
}, {
    current: 3,
    max: 5
}]; 
我怎样才能改变它

这就是我想要改变的

            var updateStars = function () {
                scope.stars = [];
                var isempty = 1;
                for (var i = 0; i < scope.max; i++) {
                    scope.stars.push({
                        filled: i < scope.ratingValue
                    });
                    isempty = 0;
                }
                if(isempty == 1)
                {
                   scope.stars.push({
                   rating: i < scope.ratingValue
                   });
                }
            };
var updateStars=函数(){
scope.stars=[];
var isempty=1;
对于(变量i=0;i
在您的
$watch
中,您有一个条件
if(newVal)
,它没有让
0
首先创建星星。:)

以下是可能的情况:

scope.$watch('ratingValue', function (oldVal, newVal) {
    if (angular.isDefined(newVal)) {
        updateStars();
    }
});

在您的
$watch
中,您有一个条件
if(newVal)
,它没有让
0
首先创建星星。:)

以下是可能的情况:

scope.$watch('ratingValue', function (oldVal, newVal) {
    if (angular.isDefined(newVal)) {
        updateStars();
    }
});

你能用你的代码制作一个plunker或一个JSFIDLE吗?你能用你的代码制作一个plunker或一个JSFIDLE吗?