在我的对象列表中,我可以激活/不活动对象。因此,一个图标是一个活动动作,另一个是非活动动作,它们都在同一个md-list中。
这就是我想要做的
代码:
<md-list ng-app="MyApp" class="listdemoListControls" ng-controller="ListCtrl">
<md-list-item ng-repeat="message in messages" ng-click='actionOne("action one")'>
<p>{{message.title}}</p>
<md-button class="md-secondary md-icon-button" ng-if="!showActionThree" ng-click="actionTwo('action two')">
Two // secondary action
</md-button>
<md-button class="md-secondary md-icon-button" ng-if="showActionThree" ng-click="actionThree('action three')">
Three // third action
</md-button>
</md-list-item>
</md-list>问题是我的actionThree函数不触发。
听起来,当我使用md-secondary类时,他创建了一个接收我的actionTwo函数的包装器,这个函数不改变。
有什么办法让这件事成功吗?
发布于 2015-09-28 20:28:36
只尝试一个按钮和三元操作符,如下所示:
<md-button class="md-secondary md-icon-button" ng-click="showActionThree ? actionThree('action three') :actionTwo('action two')">
{{showActionThree ? 'Three': 'Two'}}
</md-button>发布于 2016-03-04 16:26:20
因为你一次只需要一个按钮显示,费尔南多的答案可能是最好的。但对于其他需要多个按钮的人..。
这应该是在1.0.5,但他们改变了他们的释放过程。您可以在下一个稳定版本中等待修复,或者使用来自HEAD的最新更改。即使如此,我仍怀疑它们仍将迫使次要行动保持正确的一致.
这里有个解决办法,你可以试试。它使用ng-mouseover和ng-mouseout跟踪要执行的操作:
<md-list>
<md-list-item ng-repeat="message in messages" ng-click='rowAction(message)'>
<p>{{message.title}}</p>
<md-button class="md-icon-button" ng-mouseover="action='two'" ng-mouseout="action=null">
Two
</md-button>
<md-button class="md-icon-button" ng-mouseover="action='three'" ng-mouseout="action=null">
Three
</md-button>
</md-list-item>
</md-list>然后,在rowAction方法中,您可以执行如下操作:
$scope.rowAction = function (message){
switch($scope.action){
case 'two':
$scope.actionTwo(message);
break;
case 'three':
$scope.actionThree(message);
break;
default:
$scope.actionOne(message);
}
}https://stackoverflow.com/questions/31434491
复制相似问题