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 ng-class='{glyphicon-chevron-down:isOpened, glyphicon-chevron-right: !isOpened}'></span> {{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); }} }});
問題解答
回答1:ng-class='{’active’:selected}'1.4.5 下有效。以此類推。。單引號應該有效
回答2:第一,你的angular版本是多少?這個很關鍵!
詳細信息,參見 http://stackoverflow.com/questions/15557151/ngclass-style-with-dash-in-key
相關文章:
1. nignx - docker內nginx 80端口被占用2. docker網絡端口映射,沒有方便點的操作方法么?3. docker不顯示端口映射呢?4. javascript - nodejs調用qiniu的第三方資源抓取,返回401 bad token,為什么5. angular.js - angular內容過長展開收起效果6. docker綁定了nginx端口 外部訪問不到7. java - 為什么此私有靜態變量能被訪問呢?8. dockerfile - 我用docker build的時候出現下邊問題 麻煩幫我看一下9. docker - 各位電腦上有多少個容器啊?容器一多,自己都搞混了,咋辦呢?10. thinkphp5.1學習時遇到session問題
