Angular CSS手风琴标题

时间:2014-07-28 22:09:00

标签: css angularjs angularjs-directive

我有一支手风琴需要根据传递给它的值改变它的标题背景颜色。例如红色或绿色 在下面的示例中,我为每个商店名称都有一个标题行。如果商店停业,我需要将标题的背景标记为红色而不是绿色。我无法让它发挥作用。

   <accordion id="accordion1" close-others="true">
  <accordion-group is-open="isopen"  ng-repeat="store in stores">
       <accordion-heading class="container-fluid heading-highlight">
       {{store.StoreName}}
       </accordion-heading>
    <form name="form">
      <div class="form-row" ng-repeat="record in store.records">
       <table>
          <tr ng-formfield></tr>  //dynamic form directive
       </table>
     </div>
    </form>
  </accordion-group>
  </accordion>

我尝试使用以下指令,但无论我做了什么更改,都无效。

app.directive('headingHighlight', function () {
    return {
        restrict: 'A',
        link: function ($scope, element, attrs, controller) {
            $scope.$watch(element.children(), function () {
                var children = element.children('.panel-heading');
                for (var i = 0; i < children.length; i++) {

                        angular.element(children[i]).css('background', 'red');

                }
            });
        }
    };
});

1 个答案:

答案 0 :(得分:0)

下面的工作指令:

app.directive('headingHighlight', function () {
        return {
            restrict: 'A',
            link: function (scope, element, attrs, controller) {

                scope.$watch(element, function () {        
                    if (scope.color.Highlight != null) {
                            var panelhead = element.children('.panel-heading');
                            panelhead.css({
                                'background-image': '-webkit-linear-gradient(top,' + scope.color.Highlight +
                                ' 0%,  #e8e8e8 100%)', 'background-repeat': 'repeat-x', 'height': '85px;'
                            });
                        }

                });

            }
        };
    });