我在这里找到答案,所有的时间,但还没有张贴在多年的问题。我已经阅读了类似于当前版本的问题,但是在应用了我找到的所有提示后,仍然无法让我的代码正常工作。我正在尝试使用ng-class有条件地指定一个类,但它不起作用。角:无法获得纳克级在里面工作NG-重复
这些都是非常大的文件(所以我就交相关下面的代码),它们除了试图添加NG-类angularJS伟大的工作。我已将按钮文本作为选定属性的布尔值,以确保它正确切换,并且它确实如此。只是不适用于ng级。
在此先感谢!
HTML:
<div>
<div><em>Click buttons below to show or hide bills for each issue.</em></div>
<button ng-repeat="type in issueTypes" ng-click="toggleBtn(type.show, $index)"
class="w3-button w3-round-small w3-light-blue btn-space"
ng-class="{'testing' : type.selected}">{{type.selected}}</button>
</div>
CSS:
.testing { color: red; }
JS:
$scope.issueTypes = [{name: "Education", show: "education", selected: false}, {name: "Health Care", show: "health", selected: false},
{name: "Civil Rights", show: "civil", selected: true}, {name: "Gun Control", show: "guns", selected: false}, {name: "Women's Rights", show: "women", selected: false}];
$scope.toggleBtn = function(showString, index) {
$scope[showString] = !$scope[showString];
$scope.issueTypes[index].selected = !$scope.issueTypes[index].selected;
}
似乎是工作的罚款。我的猜测是你错过了在CSS中定义类。 – Lex
@Lex不,这是肯定在我的CSS文件。它出现在我在Chrome开发人员工具中看到的css文件中,所以我知道它在服务器上。我甚至插入了其他我认为在代码的其他地方工作的css类,以查看他们是否能够使用这个ng类,但他们不知道。这是在吹我的脑海。 –