[英]how to make directive with ng-show on the parent to trigger a function on show
[英]Make ng-show trigger if input is focued
如果標題不為空或輸入焦點,我試圖顯示“添加”按鈕。 在下面的示例中,該按鈕顯示標題是否為空,但是如果輸入焦點突出,我還要顯示該按鈕。
<input ng-model="title" />
<button ng-show="title" ng-click="add(title)">Add</button>
我正在尋找這樣的東西,但是用input_is_focused替換了。
<input ng-model="title" />
<button ng-show="title || input_is_focused" ng-click="add(title)">Add</button>
一種解決方法是添加ng-focus和ng-blur,它們調用一種方法來檢查標題是否為空,然后顯示或隱藏按鈕,但這並不是那么干凈。
剛剛為我的問題提出了一個可接受的解決方案,但可以接受其他不依賴ng-focus
和ng-blur
。
<input ng-model="title" ng-focus="focus=true" ng-blur="focus=false" />
<button ng-show="title || focus" ng-click="add(title)">Add</button>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.