样式标签中的角度

时间:2015-08-27 21:19:29

标签: javascript css angularjs

我希望有一些动态样式来容纳传入的用户徽章。 它适用于Rails,但想在Angular中做一些事情。想法?

<div ng-repeat="event in events">
<style ng-repeat="product in event.products">
  .product-id-{{ product.id }} .fa-gift { display: inline-block !important; }
  .product-id-{{ product.id }} .fa-star { display: inline-block !important; }
  .product-id-{{ product.id }} .{{ product.ticket_type }} { display: inline-block !important; }
</style>
<style ng-repeat="product in event.products" ng-if="product.ticket_type == 'golden'">
  .product-id-{{ product.id }} .{{ product.ticket_type }} { display: none !important; }
  .product-id-{{ product.id }} .icon-crown.golden { display: inline-block !important; }
</style>
<style ng-repeat="product in event.products" ng-if="product.ticket_type == 'vip'">
  .product-id-{{ product.id }} .{{ product.ticket_type }} { display: none !important; }
  .product-id-{{ product.id }} .icon-crown.golden { display: none !important; }
  .product-id-{{ product.id }} .fa-diamond.vip { display: inline-block !important; }
</style>
</div>

目前尚未解析数值。

1 个答案:

答案 0 :(得分:1)

像这样? http://jsfiddle.net/leojavier/4wwuoLxs/

<div class="field" ng-app="App">
    <table ng-controller="Controller">
        <tr ng-repeat="item in table">
            <td ng-class="item.style" ng-class="item.badge"><i ng-class="item.badge"></i> {{item.name}}</td>
        </tr>
    </table>
</div>

angular JS

var App = angular.module('App', []);
App.controller('Controller', function($scope, $timeout){
    $scope.table = [
        {name : 'Dan', deleted:false},
        {name : 'Orlando'},
        {name : 'Dany'}
   ];

    $scope.delete = function(item, index){
        item.deleted = true;
        item.style = 'deleted';

        function destroy() {
        $scope.table.splice(index, 1)
        }

        $timeout(function(){destroy();}, 3000);
    }
})

CSS

body{
    font-family:arial;
}
a{
    text-decoration:none;
    color:red;
}

table{
width:300px;
}

td{
    border:thin solid #CCC;
    padding:10px;

}

tr{
 position:relative   
     width:300px;
}

.deleted:after{
    content:'DELETED';
    position:absolute;
    top:0;
    left:0;
    background:red;
    width:300px;
    color:#FFF;
    text-align:center;
    line-height:40px;
}

您可以在此处看到它:http://jsfiddle.net/leojavier/4wwuoLxs/