你好我試圖使其應用於存儲在$root.buttonClass='btn-primary'
(例如)CSS類語法條件
<li ng-controller="controllerCtrl">
<a ng-class="{'$root.buttonClass':viewingContext=='{{entity}}'}"
ng-repeat="entity in entities"
ng-click="setContext(entity)"
type="">
<span class="label bg-info pull-right"
ng-class="{hidden:viewingContext!='{{entity}}', show:viewingContext=='{{entity}}'}">
viewing</span>
{{entity}}</a>
</li>
控制器解決以下HTML是相當簡單:
$scope.setContext = function (entity) {
console.log('set the context as: ' + entity);
if (entity == $scope.entities[0]) {
$scope.$root.buttonClass = 'btn-primary';
$scope.viewingContext = entity;
}
if (entity == $scope.entities[1]) {
$scope.$root.buttonClass = 'btn-warning';
$scope.viewingContext = entity;
}
if (entity == $scope.entities[2]) {
$scope.$root.buttonClass = 'btn-danger';
$scope.viewingContext = entity;
}
};
標記中的行可能是問題!
<a ng-class="{'$root.buttonClass':viewingContext=='{{entity}}'}"
ng-repeat="entity in entities"
ng-click="setContext(entity)"
type="">
更新:
試圖使一個js小提琴http://jsfiddle.net/gn6b4ng8/2
嘗試將引號從$ root.buttonClass中刪除 – carterw485
這似乎不起作用,但看起來似乎正確,但它不會加載類(可能現在是引導CSS問題?)' ' – darkace
當然,不能這麼難! – darkace