我在這裏找到答案,所有的時間,但還沒有張貼在多年的問題。我已經閱讀了類似於當前版本的問題,但是在應用了我找到的所有提示後,仍然無法讓我的代碼正常工作。我正在嘗試使用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類,但他們不知道。這是在吹我的腦海。 –