suchen

Heim  >  Fragen und Antworten  >  Hauptteil

angular.js - angular ng-class里面的引号问题

我有一个指令,template里面的ng-class="{glyphicon-chevron-down:isOpened, glyphicon-chevron-right: !isOpened}", 给glyphicon-chevron-down和glyphicon-chevron-right加单引号和双引号都会报错,不加引号也会报错(ng-class里面的classname如果有 - 的话要加引号的)。这种情况该怎么办呢?

.directive('brandItem', function (){
    return {
        restrict: 'EA',
        require: '^brandList',
        transclude: true,
        replace: true,
        scope: {
            title: '='
        },
        template: '<li ng-click="toggle()" class="list-group-item">'
                    +'<label><span class="glyphicon" ng-class="{glyphicon-chevron-down:isOpened, glyphicon-chevron-right: !isOpened}"></span>&nbsp;{{name}}</label>'
                    +'<p ng-transclude></p>'
                +'</li>',
        link: function (scope, element, attrs, brandListCtrl){
            scope.isOpened = false;
            brandListCtrl.addItem(scope);
            scope.toggle = function (){
                this.isOpened = !this.isOpened;
                brandListCtrl.getOpened(scope);
            }
        }
    }
});
巴扎黑巴扎黑2744 Tage vor576

Antworte allen(2)Ich werde antworten

  • 某草草

    某草草2017-05-15 16:59:14

    ng-class="{'active':selected}"
    1.4.5 下有效。以此类推。。单引号应该有效

    Antwort
    0
  • 滿天的星座

    滿天的星座2017-05-15 16:59:14

    第一,你的angular版本是多少?这个很关键!


    详细信息,参见 http://stackoverflow.com/questions/15557151/ngclass-style-with-dash-in-key

    Antwort
    0
  • StornierenAntwort