2015-11-04 68 views
0

任何人都可以請幫助什麼是在這個指令錯在這裏...Angularjs定製指令錯誤

app.directive('colorList', function ($compile) { 

    return { 
     restrict: 'AE', 
     template: "<button ng-click ='showHideColors()' type='button'>" 
      + "{{isHidden?'Show Available colors':'Hide Available colors'}}" 
      + "</button> <div ng-hide='isHidden' id='colorContainer'>" 
      + "</div>", 
     link: function ($scope, $element) { 

      $scope.isHidden = true; 
      $scope.showHideColors() = function() { 
       $scope.isHidden = !$scope.isHidden; 
      } 

      var colorContainer = $element.find('div'); 
      angular.forEach($scope.colorsArray, function (color) { 
       var appendString = "<div style = 'background-color:" + color + "'>" + color + "</div>"; 
       colorContainer.append(appendString); 
      }); 

     } 
    }; 


}); 

回答

0

我可以當場一個問題後,用下面的代碼

$scope.showHideColors() = function() { $scope.isHidden = ! scope.isHidden; } 

您已經添加了()函數名稱。因此,請將其移除,如下所示:

$scope.showHideColors = function() { $scope.isHidden = !$scope.isHidden; }