我有一个模态组件,它接受一个带有绑定的对象(ng-model)。就像是:
<modal ng-model="modals.createContact"></modal>
我正在检查$ctrl.ngModel.show
显示/隐藏模式:
<div class="modal" ng-show="$ctrl.ngModel.show" ng-transclude></div>
modals.createContact.show
我通过使用ng-click
指令设置显示/隐藏模式:
<button ng-click="modals.createContact.show = true"></button>
但是这种解决方案很难维护。
我需要一个类似这样的指令来切换模态的show
属性:
<button modal="modals.createContact">Toggle modal</button>
指令应该监听元素(按钮)的点击事件,然后切换$ctrl.modal.show
属性。
我的意思是切换是:
$ctrl.modal.show = !$ctrl.modal.show;
如何使用指令来实现这种情况?