使用ng-storage完成ng-click时如何修复按钮的颜色?

时间:2016-05-02 09:51:10

标签: html angularjs angular-ui-bootstrap

我有两个按钮。 Dettos的颜色是绿色的。当第一次按下按钮时,按钮的颜色将变为红色。但刷新按钮的颜色时会转到默认颜色。 请帮我刷新页面时如何使按钮的颜色搁浅。

<script>
  var app = angular.module('plunker', ["ngStorage"]);
  app.controller('MainCtrl', function($scope,$localStorage) {
  $scope.tablelist = [{"tablename":"t1"},{"tablename":"t2"}]
  if($localStorage.tableArray === undefined){
      $localStorage.tableArray = []
      }
  if($localStorage.tableslist===undefined){
      $localStorage.tableslist=[]
      }
  $scope.getTable=function(table){
  table.btnClass = table.btnClass == "btn-danger" ? "btn-success" : "btn-danger"
  var exists=false;
  angular.forEach($localStorage.tableArray, function (list,$index) {
    if ((list.tablename == table.tablename)) {
        console.log(list.tablename)
         console.log(table.tablename)
        exists=true;
        $localStorage.tableArray.splice($index,1)
        $localStorage.tableArray.splice($index,1)
        return false
    }
 });
 if(!exists){
      $localStorage.tableslist.push(table)
      $localStorage.tableArray=$localStorage.tableslist;
      $scope.$storage=$localStorage.tableArray
      console.log($localStorage.tableArray)
      table.color="red"
          }
     } 
});

`https://plnkr.co/edit/pSld7q89t1DCZ6l4pglZ?p=preview

1 个答案:

答案 0 :(得分:1)

每次点击都会在 ... File "/usr/local/lib/python3.4/dist-packages/matplotlib/figure.py", line 1005, in add_subplot a = subplot_class_factory(projection_class)(self, *args, **kwargs) File "/usr/local/lib/python3.4/dist-packages/matplotlib/axes/_subplots.py", line 73, in __init__ self._axes_class.__init__(self, fig, self.figbox, **kwargs) File "/usr/local/lib/python3.4/dist-packages/wcsaxes/core.py", line 49, in __init__ self.patch = self.coords.frame.patch File "/usr/local/lib/python3.4/dist-packages/wcsaxes/frame.py", line 129, in patch self._update_patch_path() File "/usr/local/lib/python3.4/dist-packages/wcsaxes/frame.py", line 115, in _update_patch_path self.update_spines() File "/usr/local/lib/python3.4/dist-packages/wcsaxes/frame.py", line 192, in update_spines self['b'].data = np.array(([xmin, ymin], [xmax, ymin])) File "/usr/local/lib/python3.4/dist-packages/wcsaxes/frame.py", line 40, in data self._world = self.transform.transform(self._data) File "/usr/local/lib/python3.4/dist-packages/wcsaxes/transforms.py", line 166, in transform world = self.wcs.wcs_pix2world(pixel_full, 1) File "/usr/local/lib/python3.4/dist-packages/astropy/wcs/wcs.py", line 1329, in wcs_pix2world 'output', *args, **kwargs) File "/usr/local/lib/python3.4/dist-packages/astropy/wcs/wcs.py", line 1231, in _array_converter return _return_single_array(xy, origin) File "/usr/local/lib/python3.4/dist-packages/astropy/wcs/wcs.py", line 1212, in _return_single_array "of shape (N, {0})".format(self.naxis)) ValueError: When providing two arguments, the array must be of shape (N, 3) 清除存储数据 事件触发,因此您必须在清除之前将存储的cssClass从该数组传递到$localStorage.tableArray。它通过以下方式与我合作:

1-将$ filter添加到控制器:

$scope.tablelist

2-在 app.controller('MainCtrl', function ($scope, $localStorage, $filter) { 之前添加以下代码:

$scope.getTable = function
  

编辑:   这是plnkr链接:   https://plnkr.co/edit/x32vQIJO6wbzZjDa77WH?p=preview