三重检查代码,无法找到错误

时间:2016-08-28 14:47:49

标签: angularjs ionic-framework

我跟随着我的一本书的教程,我的HTML编辑器一直告诉我,我的一行javascript出现了错误。我已经至少在三个不同的时间逐项检查了它,并且无法发现任何与书籍的偏差。我也去了书籍勘误页面,那里没有列出任何内容。有人可以看看这个并告诉我问题在哪里。编辑器突出显示我的控制器区域的第一行是我的问题孩子。谢谢。

// Ionic Starter App

// angular.module is a global place for creating, registering and retrieving Angular modules
// 'starter' is the name of this angular module example (also set in a <body> attribute in index.html)
// the 2nd parameter is an array of 'requires'
angular.module('starter', ['ionic'])

.run(function($ionicPlatform) {
  $ionicPlatform.ready(function() {
    if(window.cordova && window.cordova.plugins.Keyboard) {
      // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
      // for form inputs)
      cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);

      // Don't remove this line unless you know what you are doing. It stops the viewport
      // from snapping when text inputs are focused. Ionic handles this internally for
      // a much nicer keyboard experience.
      cordova.plugins.Keyboard.disableScroll(true);
    }
    if(window.StatusBar) {
      StatusBar.styleDefault();
    }
  });
})

.controller('MainCtrl', [$scope', function($scope) {
    $scope.ratingArr = [{
        value: 1,
        icon: 'ion-ios-star-outline'
        },  {
        value: 2,
        icon: 'ion-ios-star-outline'
        }, {
        value: 3,
        icon: 'ion-ios-star-outline'
        },  {
        value: 4,
        icon: 'ion-ios-star-outline'
        }, {
        value: 5,
        icon: 'ion-ios-star-outline'
        }];


$scope.setRating = function(val) {
    var rtgs = $scope.ratingArr;
    for (var i = 0; i < rtgs.length; i++ {
        if (i < val) {
            rtgs[i].icon = 'ion-ios-star';
        } else {
            rtgs[i].icon = 'ion-ios-star-outline';
        }
    };
}

}])

1 个答案:

答案 0 :(得分:0)

替换为:

for (var i = 0; i < rtgs.length; i++;) {
    if (i < val) {
        rtgs[i].icon = 'ion-ios-star';
    } else {
        rtgs[i].icon = 'ion-ios-star-outline';
    }
};