Friday, 15 May 2015

javascript - Why doesn't ng-click work when ng-blur used? -


I've used ng-click on the div and it works as expected, But when I used some other input on ng-blur , ng-click on the device stops working.

The working code is being called [addItem (item)]

  & lt; Div ng-controller = "testcontroller" & gt; & Lt; Input type = "text" ng-focus = "show = true" & gt; & Lt; Div ng-show = "show" class = "choosecont" & gt; Selected & lt; Div ng-repeat = "items in all items" ng-click = "addItem (item)" category = "select" & gt; {{Item}} & lt; / Div & gt; & Lt; / Div & gt; & Lt; Div class = "selectedcont" & gt; The following are selected & lt; Div ng-repeat = "item in selected items" class = "selected" & gt; {{Item}} & lt; / Div & gt; & Lt; / Div & gt; & Lt; / Div & gt;  

broken code [addItem (item) is not being asked)

   

related JS code

  angular Module ("myApp", []). Controller ("Test Controller", ["$ scope", Function ($ scope) {$ scope.allItems = ["A", "B", "C", "D", "E"]; $ Scope. Items visited = []; $ scope.addItem = function (item) {if ($ Scope.selectedItems.indexOf (item) == -1) $ scope.selectedItems.push (item);}}])));  

Click on the input here which will bring the dropdown. Clicking on the dropdown adds items to the selected list in one case but not in any other case.

I tried to debug that the scope is set correctly and it is accessible.

click fire after event blurring , so the list is hidden before you are able to click it. click instead of mousedown :

ng-mousedown = "addItem (item)" to use

Here is an update for your plunkr:


No comments:

Post a Comment