我正在尝试使用 ng-class 并将一个类绑定(bind)到一个表达式,这样我就可以对表达式绑定(bind)进行单元测试。但是,我似乎遗漏了什么。
按钮:
<li><a class="" ng-click="onAddInterface()"><i class="icon-plus-sign"></i> add interface </a></li>
应该折叠和展开的面板:
<div class="collapse" ng-class="{in:showCreateNewInterfacePanel}"><div>
被触发的函数
$scope.onAddInterface=function(){
$scope.showCreateNewInterfacePanel=true;
}
无论如何点击链接没有任何反应。
我错过了什么吗?
最佳答案
我不确定这是否是您真正定义 $scope.onAddInterface
函数的方式,或者它是否只是一个示例...不过您应该这样做:
$scope.onAddInterface = function() {
$scope.showCreateNewInterfacePanel = true;
}
更新
还要确保链接和可折叠元素在同一个 $scope/Controller 下:
<div ng-controller="Ctrl">
...
<a ng-click="onAddInterface()">add interface</a>
...
<div class="collapse" ng-class="{in:showCreateNewInterfacePanel}"><div>
...
</div>
Controller :
function Ctrl($scope) {
$scope.onAddInterface = function() {
$scope.showCreateNewInterfacePanel = true;
}
}
关于javascript - angular ng-class对点击没有反应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14280632/