使用ng-show和ng-click使用ng-repeat

时间:2015-10-29 23:06:56

标签: javascript angularjs ng-repeat angularjs-ng-click ng-show

我有一个颜色列表(红色,蓝色,绿色)。当每种颜色ng-click时,我想要ng-show这种颜色的阴影。

我的HTML:

<div ng-repeat='color in colors' ng-click='color.click'>
  {{color.show}}
</div>
<br><br><br>
<div ng-repeat='color in colors' ng-show='color.show'>
  <div ng-repeat='shade in color.shades'>
    {{shade}}
  </div>
</div>

我的控制器:

$scope.colors = [{
    show: 'red',
    click: 'red = true; blue = false; green = false',
    shades: [
      'dark red', 'medium red', 'light red'
    ]
  }, {
    show: 'blue',
    click: 'red = false; blue = true; green = false',
    shades: [
      'dark blue', 'medium blue', 'light blue'
    ]
  }, {
    show: 'green',
    click: 'red = false; blue = false; green = true',
    shades: [
      'dark green', 'medium green', 'light green'
    ]
  }
]

不知怎的,它不起作用。可能是将其链接到控制器。你能帮帮我吗?欢迎采用更好的方法。

这是我的Plunker

谢谢!

0 个答案:

没有答案
相关问题