如何编写没有值的可选属性来显示/隐藏某些块?
Demo
例如,当下面的行中存在“Stand”属性时:

<div ng-controller="myCtrl" showsum headers="['Table Header 1', 'Table Header 2']">

我想显示这一行(例如:Sum:12)
<td ng-show="showsum">Sum: {{ getCol1Sum() }}</td>

最佳答案

既然ng-show指令接受一个表达式,你就不能像在那里那样使用它,
ngShow指令基于
提供给ngShow属性的表达式。
我不知道你为什么把它定义为一个属性,但是你可以做的是创建一个指令
像这样

myApp.directive('showsum ', function() {
   return {
       restrict: 'A', // restrict to an attribute so we can use it as such
       link: function(scope, element, attrs) {
            scope.showsum = true; // set the show sum expression so we can access it in the scope
       }
   }
})

例子:
http://plnkr.co/edit/mE5LrSMWdIwPRazEdD3b?p=preview
它将为作用域创建一个showsum属性,您可以使用它执行所需的操作

07-24 17:46
查看更多