2014-02-19 62 views
0

我的问题很简单。我正在使用AngularJS中的ng-switch,并试图获取ng-switch-何时从我的beenAdded()函数返回的变量,该函数在父级ng-switch“on”指令中调用。它似乎并没有接受价值。有没有办法使用函数ng-if?有任何想法吗?使用ng开关功能

谢谢!

在我的HTML:

<span ng-switch on="beenAdded(id)"> 
    <span ng-switch-when="false"> 
     //do something 
    </span> 
</span> 

在我的控制器:

$scope.beenAdded = function(var) { 
    if (some logic here){ 
     return true; 
    else { 
     return false; 
    } 
} 
+0

这应该工作。缺少“在表达中是否是一个错字? –

回答

2

你能使用ng-if呢?

<span ng-if="beenAdded(id) == false"> 
    //do something 
</span> 

而且工作jsFiddle